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?
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
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

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.