+ Reply to Thread
Results 1 to 6 of 6

Macro to open and close an Excel file

  1. #1
    Magnivy
    Guest

    Macro to open and close an Excel file

    I would like to create a macro that would open an Excel file based on file
    path that is indicated in a cell, and then close it. For instance, open the
    file for which the file path is indicated in cell A1, and then close it.

    Any advice you could provide on this would be greatly appreciated.

    Magnivy

  2. #2
    Bob Phillips
    Guest

    Re: Macro to open and close an Excel file

    workbooks.open Range("A1").Value
    ...
    activeworkbook.close

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Magnivy" <Magnivy@discussions.microsoft.com> wrote in message
    news:302EB7D8-F94E-4D52-BDDA-8B1C23C90573@microsoft.com...
    > I would like to create a macro that would open an Excel file based on file
    > path that is indicated in a cell, and then close it. For instance, open

    the
    > file for which the file path is indicated in cell A1, and then close it.
    >
    > Any advice you could provide on this would be greatly appreciated.
    >
    > Magnivy




  3. #3
    Registered User
    Join Date
    02-24-2006
    Posts
    24
    dim openwb as workbook
    workbooks.open filename:=Range("A1")
    set openwb=activeworkbook
    openwb.close

    Quote Originally Posted by Magnivy
    I would like to create a macro that would open an Excel file based on file
    path that is indicated in a cell, and then close it. For instance, open the
    file for which the file path is indicated in cell A1, and then close it.

    Any advice you could provide on this would be greatly appreciated.

    Magnivy

  4. #4
    Henrich
    Guest

    RE: Macro to open and close an Excel file

    Hi, try this:

    Sub File_Open()
    file=Range("A1")
    Workbooks.Open Filename:= file
    ActiveWindow.Close
    End Sub

    ‚ÄěMagnivy" nap√*sal (nap√*sala):

    > I would like to create a macro that would open an Excel file based on file
    > path that is indicated in a cell, and then close it. For instance, open the
    > file for which the file path is indicated in cell A1, and then close it.
    >
    > Any advice you could provide on this would be greatly appreciated.
    >
    > Magnivy


  5. #5
    Jim Thomlinson
    Guest

    RE: Macro to open and close an Excel file

    Try this...

    Sub OpenClose()
    Dim wbk As Workbook

    On Error Resume Next
    Set wbk = Workbooks.Open(Sheets("Sheet1").Range("A1"))
    On Error GoTo 0

    If wbk Is Nothing Then Exit Sub

    MsgBox wbk.Name & " is open."
    wbk.Close

    MsgBox "And now it is closed."
    Set wbk = Nothing
    End Sub
    --
    HTH...

    Jim Thomlinson


    "Magnivy" wrote:

    > I would like to create a macro that would open an Excel file based on file
    > path that is indicated in a cell, and then close it. For instance, open the
    > file for which the file path is indicated in cell A1, and then close it.
    >
    > Any advice you could provide on this would be greatly appreciated.
    >
    > Magnivy


  6. #6
    Magnivy
    Guest

    Re: Macro to open and close an Excel file

    Many thanks to everyone for your help!! kwiklearner's code seems to work best
    for me.

    Magnivy
    "kwiklearner" wrote:

    >
    > dim openwb as workbook
    > workbooks.open filename:=Range("A1")
    > set openwb=activeworkbook
    > openwb.close
    >
    > Magnivy Wrote:
    > > I would like to create a macro that would open an Excel file based on
    > > file
    > > path that is indicated in a cell, and then close it. For instance, open
    > > the
    > > file for which the file path is indicated in cell A1, and then close
    > > it.
    > >
    > > Any advice you could provide on this would be greatly appreciated.
    > >
    > > Magnivy

    >
    >
    > --
    > kwiklearner
    > ------------------------------------------------------------------------
    > kwiklearner's Profile: http://www.excelforum.com/member.php...o&userid=31909
    > View this thread: http://www.excelforum.com/showthread...hreadid=521717
    >
    >


+ 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