+ Reply to Thread
Results 1 to 2 of 2

Thread: How to close open workbooks from an application get open filename call ?

  1. #1
    Registered User
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 2007
    Posts
    65

    How to close open workbooks from an application get open filename call ?

    Hi - here is part of the code that I am using. When I have run my complete macro this file that I select as per the code below always remains open when I am done using the macro to perform its task. Can someone help me with a bit of code that could put at the end of macro to ensure all files are closed when procedure has been completed ?

    Many thanks


    MFile = ActiveWorkbook.Name
    Application.ScreenUpdating = False
    proceed:
    WeeklyFN = Application.GetOpenFilename(fileFilter:="All files (*.*), *.*", Title:="Please open the GT Feed")
    If WeeklyFN = "" Then
        MsgBox "You have not selected a file."
        GoTo proceed
    Else
        Workbooks.Open Filename:=WeeklyFN
        WeeklyFN = ActiveWorkbook.Name
    End If

  2. #2
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    2,998

    Re: How to close open workbooks from an application get open filename call ?

    Dim WeeklyFNBook as Workbook
    
    MFile = ActiveWorkbook.Name
    Application.ScreenUpdating = False
    proceed:
    WeeklyFN = Application.GetOpenFilename(fileFilter:="All files (*.*), *.*", Title:="Please open the GT Feed")
    If WeeklyFN = "" Then
        MsgBox "You have not selected a file."
        GoTo proceed
    Else
        Set WeeklyFNBook = Workbooks.Open Filename:=WeeklyFN:Rem Changed <<<<<<<<<<<<<<<<<
        WeeklyFN = WeeklyFNBook.Name: Rem changed <<<<
    End If
    
    Rem do stuff
    
    WeeklyFNBook.Close
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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.2.0