+ Reply to Thread
Results 1 to 4 of 4

Closing an open workbook

  1. #1
    Dan
    Guest

    Closing an open workbook

    Trying to close an open workbook that is not the active workbook. It was
    opened for reference as a looked but after I obtain the information I need I
    want to close it.

    'working file
    myFileName = Application.GetOpenFilename("Text Files, *.txt")

    'refernce file
    VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")

    code here...

    'close reference file
    Workbooks(VMM_FileName).Activate
    ActiveWorkbook.Close False

    With this I get Run-time error '9': Subscript out of range

    Thanks

  2. #2
    Bob Phillips
    Guest

    Re: Closing an open workbook

    Try this

    'working file
    myFileName = Application.GetOpenFilename("Text Files, *.txt")

    'refernce file
    VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")
    Set VMM_WB = Worksbooks.open(VMM_Filename)

    code here...

    'close reference file
    VMM_WB.Close False


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Dan" <[email protected]> wrote in message
    news:[email protected]...
    > Trying to close an open workbook that is not the active workbook. It was
    > opened for reference as a looked but after I obtain the information I need

    I
    > want to close it.
    >
    > 'working file
    > myFileName = Application.GetOpenFilename("Text Files, *.txt")
    >
    > 'refernce file
    > VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")
    >
    > code here...
    >
    > 'close reference file
    > Workbooks(VMM_FileName).Activate
    > ActiveWorkbook.Close False
    >
    > With this I get Run-time error '9': Subscript out of range
    >
    > Thanks




  3. #3
    Dan
    Guest

    Re: Closing an open workbook

    For some reason thie created an error. When I changed it to

    Set VMM_Workbook = ActiveWorkbook
    .....
    VMM_Workbook.Activate
    ActiveWorkbook.Close False

    This worked. Thanks

    "Bob Phillips" wrote:

    > Try this
    >
    > 'working file
    > myFileName = Application.GetOpenFilename("Text Files, *.txt")
    >
    > 'refernce file
    > VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")
    > Set VMM_WB = Worksbooks.open(VMM_Filename)
    >
    > code here...
    >
    > 'close reference file
    > VMM_WB.Close False
    >
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (replace somewhere in email address with gmail if mailing direct)
    >
    > "Dan" <[email protected]> wrote in message
    > news:[email protected]...
    > > Trying to close an open workbook that is not the active workbook. It was
    > > opened for reference as a looked but after I obtain the information I need

    > I
    > > want to close it.
    > >
    > > 'working file
    > > myFileName = Application.GetOpenFilename("Text Files, *.txt")
    > >
    > > 'refernce file
    > > VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")
    > >
    > > code here...
    > >
    > > 'close reference file
    > > Workbooks(VMM_FileName).Activate
    > > ActiveWorkbook.Close False
    > >
    > > With this I get Run-time error '9': Subscript out of range
    > >
    > > Thanks

    >
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Closing an open workbook

    In my example it was VMM_WB not VMM_Workbook. Did you use that throughout,
    and declare it as type Workbook?

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Dan" <[email protected]> wrote in message
    news:[email protected]...
    > For some reason thie created an error. When I changed it to
    >
    > Set VMM_Workbook = ActiveWorkbook
    > ....
    > VMM_Workbook.Activate
    > ActiveWorkbook.Close False
    >
    > This worked. Thanks
    >
    > "Bob Phillips" wrote:
    >
    > > Try this
    > >
    > > 'working file
    > > myFileName = Application.GetOpenFilename("Text Files, *.txt")
    > >
    > > 'refernce file
    > > VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")
    > > Set VMM_WB = Worksbooks.open(VMM_Filename)
    > >
    > > code here...
    > >
    > > 'close reference file
    > > VMM_WB.Close False
    > >
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (replace somewhere in email address with gmail if mailing direct)
    > >
    > > "Dan" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Trying to close an open workbook that is not the active workbook. It

    was
    > > > opened for reference as a looked but after I obtain the information I

    need
    > > I
    > > > want to close it.
    > > >
    > > > 'working file
    > > > myFileName = Application.GetOpenFilename("Text Files, *.txt")
    > > >
    > > > 'refernce file
    > > > VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")
    > > >
    > > > code here...
    > > >
    > > > 'close reference file
    > > > Workbooks(VMM_FileName).Activate
    > > > ActiveWorkbook.Close False
    > > >
    > > > With this I get Run-time error '9': Subscript out of range
    > > >
    > > > Thanks

    > >
    > >
    > >




+ 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