+ Reply to Thread
Results 1 to 5 of 5

Macro to close open files without saving it

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Macro to close open files without saving it

    When you open the workbook assign it to a variable:

    
    Dim WorkbookToOpen as Workbook
    
    set WorkbooktoOpen = workbooks.open(Filetoopen)
    Then, to close the workbook you simply:

    
    Application.Displayalerts = false
    WorkbookToOpen.close
    Application.displayalerts = true

  2. #2
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: Macro to close open files without saving it

    Hi

    i am trying to make easy your code
    try
    Sub Open_ExistingWorkbook()
    Dim TempWnd As Workbook, fName As String
    Dim r As Range
        
        For Each r In Sheets("Data extraction").Range("B7:B14")
            If r.Address = "$B$7" Then
                filetoopen = ThisWorkbook.Worksheets("data extraction").Range("b7")
                fName = Dir(filetoopen)
                Workbooks.Open Filename:=filetoopen
                Set TempWnd = Workbooks(fName)
                Sheets("Payspace").Visible = True
                Sheets("Payspace").Select
                Range("A4:D117").Copy ThisWorkbook.Sheets("Alrode").Range("A" & Range("A" & Rows.Count).End(xlUp).Row).Offset(5)
                TempWnd.Close False
            End If
            
            If r.Address = "$B$8" Then
                    filetoopen = ThisWorkbook.Worksheets("data extraction").Range("b8")
                    fName = Dir(filetoopen)
                    Workbooks.Open Filename:=filetoopen
                    Set TempWnd = Workbooks(fName)
                    
                    Sheets("Payspace").Visible = True: Sheets("Payspace").Range("A4").Select
                    TempWnd.Close False
                     
            End If
            
        Next r
        
     End Sub
    Regards,
    MohanS


    "Perfection is not attainable, but if we chase perfection we can catch excellence." - Vince Lombardi

    You can simply say thanks by clicking "*Add Reputation" icon

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Open and close files using excel macro
    By laxmanann in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-16-2014, 12:06 PM
  2. [SOLVED] macro to open all files in a folder, save them, then close them
    By hopefulhart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2013, 06:40 PM
  3. [SOLVED] Macro to open and close all files in a folder and sub folders
    By BillDoor in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-31-2012, 06:51 AM
  4. Macro to open, copy/paste, and close files with variable name
    By mjr33 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-15-2011, 10:20 PM
  5. Macro to Open, Save and Close Excel Files
    By az! in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2011, 04:19 AM
  6. Macro to Open, Print and Close multiple PDF Files
    By Herve_Rob in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-09-2009, 05:08 AM
  7. Macro to open all files, make changes, save and close
    By certain_death in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2009, 03:42 PM

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