Save if Modified Before Print

Lace29M

New Member
Joined
Jul 20, 2007
Messages
5
I need to create a command to tell Excel to Save my Workbook BeforePrint, if and only if the Workbook has been modified since the last time it was saved. Right now I have a command that runs where a text box is populated with the last date modified BeforeSave. The date modified will not change unless modifications to the workbook are saved. Therefore, I want to keep the last date modified the same when the Workbook is opened and printed if the Workbook has not been modified. Please Help!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Derek Brown

Well-known Member
Joined
Dec 26, 2005
Messages
2,390
Do you mean something like:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim wb As Workbook
If Not wb.Saved Then
    wb.Save
End If
Set wb = Nothing
End Sub

placed in the 'ThisWorkbook' VBA object?
 

Derek Brown

Well-known Member
Joined
Dec 26, 2005
Messages
2,390
Just for the record, the line
Code:
Set wb = ThisWorkbook
should have been included before the IF statement
 

Forum statistics

Threads
1,181,102
Messages
5,928,069
Members
436,586
Latest member
latintxn

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
Top