Well, this code will delete the event. You save a copy of your workbook, so my idea is
- you do whatever you do
- Delete the Workbook_open Macro
- Save to a new workbook (that part of macro won't be)
- DO NOT SAVE CHANGES IN YOUR ORIGINAL WORKBOOK, so the Workbook_Open macro will be always secure.
Anyways, test it first several times to make sure it works. Altering VBA code with VBA itself can produce weird things somethimes.
Hope this helps.
All credits go to OZGRIZ
Also, make sure you check in Excel Options->Trusted Sites->Settings of Trusted Sites-> Macros Setting-> Check Trust access to Visual Basic Editor
Sub DeleteWorkbookEventCode()
''Needs Reference Set To _
'"Microsoft Visual Basic For Applications Extensibility"
'Tools>References.
'Also, make sure you check in Excel Options->Trusted Sites->Settings of Trusted Sites-> Macros Setting-> Check Trust access to Visual Basic Editor
Dim i As Integer
Dim MyStart, MyEnd As Integer
With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
MyStart = 0
For i = 1 To .CountOfLines Step 1
If .Lines(i, 1) = "Private Sub Workbook_Open()" Then MyStart = i
If .Lines(i, 1) = "End Sub" And MyStart > 0 Then
MyEnd = i
Exit For
End If
Next i
.DeleteLines MyStart, (MyEnd - MyStart) + 1
End With
End Sub
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…