+ Reply to Thread
Results 1 to 5 of 5

close inactive file

Hybrid View

  1. #1
    Registered User
    Join Date
    06-05-2009
    Location
    Charlotte
    MS-Off Ver
    Excel 2007
    Posts
    19

    close inactive file

    I'm using the
    application.getopenfilename
    method to browse and open a file. i then copy some data to another file. My problem is that I can't seem to close that same file I opened with the get mthod. i know how to use the
    activewindow.close
    proceedure to close the active window, but the file I want to close is not active at the time it needs to be closed, and I'll never know the name of the file since people name their files differently.


    Heres my basic code:

    NewFN1 = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please Select Lock Detail Report")
    If NewFN1 = False Then
    ' They pressed Cancel
    MsgBox "Stopping, no file selected."
    Exit Sub
    Else
    Workbooks.Open Filename:=NewFN1
    End If
    
    Sheets("DownLoadReports").Select
        Cells.Select
        Selection.Copy
        Windows("monthly servicing prep.xls").Activate
        Sheets("Sheet1").Select
        Range("A1").Select
        Selection.PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False

    JS

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: close inactive file

    Hello JS,

    Since the file you opened is a workbook, you can close the file this way...
    NewFN1 = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please Select Lock Detail Report")
    If NewFN1 = False Then
    ' They pressed Cancel
    MsgBox "Stopping, no file selected."
    Exit Sub
    Else
    Workbooks.Open Filename:=NewFN1
    End If
    
    Sheets("DownLoadReports").Select
        Cells.Select
        Selection.Copy
        Windows("monthly servicing prep.xls").Activate
        Sheets("Sheet1").Select
        Range("A1").Select
        Selection.PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    
    Workbooks(Workbooks(NewFN1).Name).Close SaveChanges:=True
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-05-2009
    Location
    Charlotte
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: close inactive file

    That doesn't work either.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: close inactive file

    Hello jseufert,

    I must have not looked at your profile. It says you are using Excel 2007. The code I provided works in 2003. Which version is the workbook running?

  5. #5
    Registered User
    Join Date
    06-05-2009
    Location
    Charlotte
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: close inactive file

    The solution or work-around is to create a temp file that can be closed and later killed.

+ 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