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
Bookmarks