+ Reply to Thread
Results 1 to 3 of 3

Auto closing a specific workbook

  1. #1
    Registered User
    Join Date
    03-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    7

    Auto closing a specific workbook

    I have open a master workbook. I am using Application.GetOpenFilename to allow the user to select and open another workbook from which data is extracted via vba. Once this is done I want this file to be closed - I think I need the filename, rather than filepath to achieve this.

    I have tried using MyName = ThisWorkbook.Name once the book has been opened, but it always seem to return the name for the masterbook. Is there a way to extract the filename from the opened filepath, or otherwise close it?

    It will not necessarily be the active book either.

    Thanks
    Last edited by Jimmy Moggles; 03-29-2011 at 08:38 AM. Reason: SOLVED

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Auto closing a specific workbook

    Store a reference to the workbook when you open it:
    Please Login or Register  to view this content.
    for example.

    FYI, the issue with your code is you want Activeworkbook rather than ThisWorkbook - the latter refers to the workbook containing the code.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    03-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Auto closing a specific workbook

    I had similar code to yours but you were right in that my fatal mistake was using ThisWorkbook rather than Activeworkbook... :p All works perfectly now thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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