Opening another workbook forces current one to be unsaved

Ludwig

Board Regular
Joined
Apr 7, 2003
Messages
90
Office Version
  1. 365
Platform
  1. Windows
I have a Sub Workbook_Open() routine that when I include
VBA Code:
Workbooks.Open ThisWorkbook.Path & "\" & WkBkView
statement, the "WkBkView" workbook happily opens but the macro workbook Saved state gets set to False.

What's weird is despite setting the macro workbook state back to True on the next line, it immediately still reports False. If comment out the Open statement this does not occur.

My code at this point ..
VBA Code:
Debug.Print "2: " & Workbooks(MyWorkBookName).Saved & " .. " & MyWorkBookName & " =? " & ThisWorkbook.Name & "."
    Workbooks(MyWorkBookName).Saved = True
Debug.Print "3: " & Workbooks(MyWorkBookName).Saved & " .. " & MyWorkBookName & " =? " & ThisWorkbook.Name & "."
and the resultant prints ..

2: False .. TEST Update.xlsm =? TEST Update.xlsm.
3: False .. TEST Update.xlsm =? TEST Update.xlsm.

PS: using ThisWorkbook.Saved behaves exactly the same.

What is causing this behaviour, and how can I avoid it?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Volatile formulas such as TODAY(), NOW(), RAND() and the like may be the cause.

Artik
 
Upvote 0
Solution
Volatile formulas such as TODAY(), NOW(), RAND() and the like may be the cause.

Artik
I don't use any of those, but your reply prompted me to realise I have a "CELL(...." function call that fills in the workbook name. It's almost the only function called, everything else is text description and .. the macros that work on "the other" workbook.

Easily fixed .. will replace this with VBA in Sub Workbook_Open - to replace cell string value if it doesn't match the current name, otherwise leave it alone ie no need to re-save every time.

Reason I do this is so the macros in this workbook will open the workbook with same name with text "Update" on the end replaced with "View". i.e. can copy XLSM and give it another name to do the same stuff on a different version of the "non-macro" workbook.

So thanks, you've sorted my problem! Many many thanks.
 
Upvote 0

Forum statistics

Threads
1,215,474
Messages
6,125,026
Members
449,204
Latest member
LKN2GO

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top