Suppressing the need for a Save after running a macro?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Good morning!

I have a potentially stupid question today. I use the following macro to copy and paste data to the clipboard for pasting outside of Excel:

VBA Code:
Sub CopyShippingInstructions()

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Sheets("ShippingInstructions").Visible = True
    
    Sheets("ShippingInstructions").Range("A1") = Cells(ActiveCell.Row, "B")
    Sheets("ShippingInstructions").Range("E1") = Cells(ActiveCell.Row, "E")
    Sheets("ShippingInstructions").Select
    Range("ShippingInstructions").Select
    Selection.Copy
    
    Sheets("Calendar").Select
 
    Sheets("ShippingInstructions").Visible = False
 
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
 
End Sub

If I run this macro immediately after opening the Workbook it will appear as though the Workbook has been edited. It will ask to be saved upon closing, even though I never changed any data that would need a save. Make sense?

Is it possible to add something to my code to let it know that nothing has been changed by the macro?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi jmpatrick,

if you add the codeline

VBA Code:
ThisWorkbook.Save

which would save the workbook or

VBA Code:
ThisWorkbook.Saved = True

before the end of the procedure to set the status to no changes made/workbook is saved. Please mind the difference between ThisWorkbook (workbook with code) and ActiveWorkbook (any active workbook in Excel, must not be the workbook with code).

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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