Adding "WorkbookOpen" Code Programmatically
A simple example
'----------------------------------------------------------------
Sub AddWorkbookEventProc()
'----------------------------------------------------------------
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("Open", "Workbook") + 1
.InsertLines StartLine, _
"Dim ans" & vbCrLf & _
" ans = Msgbox( ""All OK"",vbYesNo)" & vbCrLf & _
" If ans = vbNo Then myVar = True"
End With
End Sub
--
HTH
Bob Phillips
(remove xxx from email address if mailing direct)
wrote in message
oups.com...
I'm trying to, I suppose for want of a better description, paste a
WorbookOpen sub-routine into 'ThisWorkbook' component of a project in a
new workbook.
Basically I use shell files that refresh data from Access/Oracle
tables, add any necessary formatting, then copy an array of sheets to a
new workbook. I have since created some additional code that allows me
to track who opens these final reports and the frequency.
I have no trouble importing my .bas file, however adding the code to
ThisWorkbook to call the sub-routine on WorkbookOpen is causing issues.
Can anyone assist?
MT
|