Adding "WorkbookOpen" Code Programmatically

  • Thread starter Thread starter tyasm
  • Start date Start date
T

tyasm

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
 
A simple example

'----------------------------------------------------------------
Sub AddWorkbookEventProc()
'----------------------------------------------------------------
Dim StartLine As Long

With ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top