Results 1 to 10 of 21

Thread: Close All Open Excel Files With VBA Open Close File issue unsolved

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    I see 2 problems

    Problem 1 – text in VBA code
    In VBA we must tell the coding that we want to give it a text
    We do it like this ....... " Here is text "

    Book1.xlsm is the text name , so we tell VBA that it is text like this
    Book1.xlsm


    Problem 2 Nothing

    Nothing
    is special in VBA . It makes an object empty
    Here are 3 macros to help explain what Nothing is...

    This macro will work
    Code:
    Sub TestNothing1()
    Dim Wb As Workbook
     Set Wb = ThisWorkbook
    MsgBox prompt:="My text name for Wb is  " & Wb.Name
    End Sub
    This next code will error: It will not work. It will not work because you make Wb empty with Nothing
    Code:
    Sub TestNothing2()
    Dim Wb As Workbook
     Set Wb = ThisWorkbook
     Set Wb = Nothing
    MsgBox prompt:="My text name for Wb is  " & Wb.Name
    End Sub
    This next macro will work
    Code:
    Sub TestNothing3()
    Dim Wb As Workbook
     Set Wb = ThisWorkbook
     Set Wb = Nothing
     Set Wb = ThisWorkbook
     MsgBox prompt:="My text name for Wb is  " & Wb.Name
    End Sub

    If you want nothing to be done, then put no coding - no coding= nothing will be done








    So try
    Code:
    Sub STEP1()
    Dim AnyWb As Workbook
        For Each AnyWb In Workbooks
            If AnyWb.Name <> "Book1.xlsm" Then
            '  put nothing here . So no code is here   so nothing is done
            Else
            AnyWb.Close Savechanges = True
            End If
        Next AnyWb
    End Sub

    Or just like this - no coding= nothing will be done
    Code:
    Sub STEP1()
    Dim AnyWb As Workbook
        For Each AnyWb In Workbooks
            If AnyWb.Name <> "Book1.xlsm" Then
            
            Else
            AnyWb.Close Savechanges = True
            End If
        Next AnyWb
    End Sub
    Last edited by DocAElstein; 03-03-2020 at 04:00 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Replies: 1
    Last Post: 02-19-2015, 03:49 AM
  2. Replies: 4
    Last Post: 04-10-2014, 10:58 PM
  3. Replies: 6
    Last Post: 09-07-2013, 03:40 PM
  4. Replies: 15
    Last Post: 08-23-2013, 12:03 PM
  5. Replies: 4
    Last Post: 06-09-2013, 01:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •