+ Reply to Thread
Results 1 to 6 of 6

OPen and close file

  1. #1
    Alvin Hansen
    Guest

    OPen and close file

    Hi!

    Hope someone can help with a inputbox
    there shall contain a file name, when click
    i want to close the file I work with now, and
    open the other file there are written in the inputbox.

    Best regards alvin


  2. #2
    Chip Pearson
    Guest

    Re: OPen and close file

    Alvin,

    Try the following code:


    Dim FName As Variant
    FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
    If FName <> False Then
    Workbooks.Open FName
    ThisWorkbook.Close
    End If



    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com




    "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in
    message
    news:3B8E7CBA-F146-4390-8319-0061914E7355@microsoft.com...
    > Hi!
    >
    > Hope someone can help with a inputbox
    > there shall contain a file name, when click
    > i want to close the file I work with now, and
    > open the other file there are written in the inputbox.
    >
    > Best regards alvin
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: OPen and close file

    If the code is in the file you want to close, the code stops when the
    workbook is closed

    Dim wkbkOld as Workbook, wkbk as Workbook
    set wkbkOld = ActiveWorkbook
    fname = Application.GetOpenfileName
    if fName <> False then
    set wkbk = Workbooks.Open(fName)
    end if
    wkbk.Close Savechanges:=True

    --
    Regards,
    Tom Ogilvy

    "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    news:3B8E7CBA-F146-4390-8319-0061914E7355@microsoft.com...
    > Hi!
    >
    > Hope someone can help with a inputbox
    > there shall contain a file name, when click
    > i want to close the file I work with now, and
    > open the other file there are written in the inputbox.
    >
    > Best regards alvin
    >




  4. #4
    Alvin Hansen
    Guest

    Re: OPen and close file

    Hi
    I very try this but i can't

    i have
    Application.GetOpenFilename ("excel files (*.xls)","c:\city
    breaks\priser\usa\order")

    but i can't get i to work , what i want is to look after the file in the
    place
    c:\city breaks\priser\usa\order how do i write this
    i can open in dokument and so on.

    Alvin


    "Chip Pearson" skrev:

    > Alvin,
    >
    > Try the following code:
    >
    >
    > Dim FName As Variant
    > FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
    > If FName <> False Then
    > Workbooks.Open FName
    > ThisWorkbook.Close
    > End If
    >
    >
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    >
    >
    > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in
    > message
    > news:3B8E7CBA-F146-4390-8319-0061914E7355@microsoft.com...
    > > Hi!
    > >
    > > Hope someone can help with a inputbox
    > > there shall contain a file name, when click
    > > i want to close the file I work with now, and
    > > open the other file there are written in the inputbox.
    > >
    > > Best regards alvin
    > >

    >
    >
    >


  5. #5
    Tom Ogilvy
    Guest

    Re: OPen and close file

    Dim FName As Variant
    Dim sStr as String
    sStr = "c:\citybreaks\priser\usa\order"
    chdrive sStr
    chdir sStr
    FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
    If FName <> False Then
    Workbooks.Open FName
    ThisWorkbook.Close
    End If

    --
    Regards,
    Tom Ogilvy


    "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    news:BFE690A4-E3E0-4F57-9A6B-687B42217C58@microsoft.com...
    > Hi
    > I very try this but i can't
    >
    > i have
    > Application.GetOpenFilename ("excel files (*.xls)","c:\city
    > breaks\priser\usa\order")
    >
    > but i can't get i to work , what i want is to look after the file in the
    > place
    > c:\city breaks\priser\usa\order how do i write this
    > i can open in dokument and so on.
    >
    > Alvin
    >
    >
    > "Chip Pearson" skrev:
    >
    > > Alvin,
    > >
    > > Try the following code:
    > >
    > >
    > > Dim FName As Variant
    > > FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
    > > If FName <> False Then
    > > Workbooks.Open FName
    > > ThisWorkbook.Close
    > > End If
    > >
    > >
    > >
    > > --
    > > Cordially,
    > > Chip Pearson
    > > Microsoft MVP - Excel
    > > Pearson Software Consulting, LLC
    > > www.cpearson.com
    > >
    > >
    > >
    > >
    > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in
    > > message
    > > news:3B8E7CBA-F146-4390-8319-0061914E7355@microsoft.com...
    > > > Hi!
    > > >
    > > > Hope someone can help with a inputbox
    > > > there shall contain a file name, when click
    > > > i want to close the file I work with now, and
    > > > open the other file there are written in the inputbox.
    > > >
    > > > Best regards alvin
    > > >

    > >
    > >
    > >




  6. #6
    Alvin Hansen
    Guest

    Re: OPen and close file

    Thanks for the help Tom
    it's working but the first workbook dosn't close
    before i close all ??

    I hav try many things but it dosn't close when i open the
    next workbook ??

    Best regards alvin


    "Tom Ogilvy" skrev:

    > Dim FName As Variant
    > Dim sStr as String
    > sStr = "c:\citybreaks\priser\usa\order"
    > chdrive sStr
    > chdir sStr
    > FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
    > If FName <> False Then
    > Workbooks.Open FName
    > ThisWorkbook.Close
    > End If
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in message
    > news:BFE690A4-E3E0-4F57-9A6B-687B42217C58@microsoft.com...
    > > Hi
    > > I very try this but i can't
    > >
    > > i have
    > > Application.GetOpenFilename ("excel files (*.xls)","c:\city
    > > breaks\priser\usa\order")
    > >
    > > but i can't get i to work , what i want is to look after the file in the
    > > place
    > > c:\city breaks\priser\usa\order how do i write this
    > > i can open in dokument and so on.
    > >
    > > Alvin
    > >
    > >
    > > "Chip Pearson" skrev:
    > >
    > > > Alvin,
    > > >
    > > > Try the following code:
    > > >
    > > >
    > > > Dim FName As Variant
    > > > FName = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
    > > > If FName <> False Then
    > > > Workbooks.Open FName
    > > > ThisWorkbook.Close
    > > > End If
    > > >
    > > >
    > > >
    > > > --
    > > > Cordially,
    > > > Chip Pearson
    > > > Microsoft MVP - Excel
    > > > Pearson Software Consulting, LLC
    > > > www.cpearson.com
    > > >
    > > >
    > > >
    > > >
    > > > "Alvin Hansen" <AlvinHansen@discussions.microsoft.com> wrote in
    > > > message
    > > > news:3B8E7CBA-F146-4390-8319-0061914E7355@microsoft.com...
    > > > > Hi!
    > > > >
    > > > > Hope someone can help with a inputbox
    > > > > there shall contain a file name, when click
    > > > > i want to close the file I work with now, and
    > > > > open the other file there are written in the inputbox.
    > > > >
    > > > > Best regards alvin
    > > > >
    > > >
    > > >
    > > >

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1