Compile Error when using the workbook_open event

mark100

New Member
Joined
Oct 23, 2006
Messages
2
I have a workbook that contains the code below in the 'ThisWorkbook' module:

Private Sub Workbook_Open()
On Error GoTo MyErrorHandler
Call manipulate
Me.Save

Line1:

Exit Sub

MyErrorHandler:

Resume Line1

End Sub


I want the workbook to execute the 'manipulate' macro the first time the workbook is opened and then never again.

To try and acheive this I have set up the 'manipulate' macro to delete the module it is inside at the end of its procedure. However, this causes a problem when the workbook is next opened as the call fails because the macro is missing, resulting in the Compile error 'Sub or function not defined'.

I have tried to use an error handler to exit the code, skipping the save line, in the hope that it would open the spreadsheet, but it just keeps returning to the Compile Error message.

Has anyone any suggestions on how I can get around this? If my coding or explanation is poor it is because I am new to VBA, so please be gentle.

From a confused Mark
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I have managed to sort this out by keeping the 'manipulate' macro and adding the statement

If ThisWorkbook.Name <> "MyWorkbookName.xls" Then Exit Sub

to the 'ThisWorkbook' module code.

It works as the 'manipulate' macro forces the user to save the workbook with a new name, therfore when the new workbook is subsequently opened it will end the procedure before running the macro.

I found the code on an Ozgrid.com forum posted by a royUK.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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