Excel, VBA, Remove/Deactivate SubRoutine


I have a macro that upon opening a workbook, prints the workbook to a pdf and closes the workbook again.  This is great initially but going forward I don't want the workbook to complete this step each time the workbook is opened.  Ideally I would like the macro to complete the required steps open open and the deactivate the sub routine going forward.

I tried running some code to delete all the vba code from the workbook but this takes way to long.

Any ideas?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
Hello Tbyrd,

The macro could write a value into a cell in a hidden sheet after it has printed the PDF.

Before the macro starts, it should check if the cell in the hidden sheet contains the stop value and then exit the sub or continue with it.

Something like the code below.

cheers, teylyn

Option Explicit

Private Sub Workbook_Open()
If Worksheets("Sheet3").Range("A1").Value = "printed" Then Exit Sub

' your code here

Worksheets("Sheet3").Range("A1").Value = "printed"
End Sub

Open in new window

You could also use a message box at an appropriate point in the routine, and show "continue" and "cancel" buttons.  Hit continue to process the routine as is, and hit cancel to triger an 'exit sub' clause

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
What's wrong with my suggestion? It does exactly what you describe in the question, with no user interaction.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.