View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Import a CodeModule then call its method in Workbook_Open()

The problem is that you get a compile error, so you need to get around that.
Luckily, if the call to KickStart is in another module, it overcomes the
compile error.

So, what you need to do is add a module that will always be in the workbook
(that is, not imported on open) with a procedure that calls KickStart (that
is all it will do). Assuming this procedure is called CallImportedMacro,
then your open code would be

Private Sub Workbook_Open()

Me.VBProject.VBComponents.import "c:\CodeFile.bas"

Call CallImportedMacro

End Sub


in the code module you would have

Public Sub CallImportedMacro()
Call kickStart
End Sub


An alternative way is to Application.Run it

Private Sub Workbook_Open()

Me.VBProject.VBComponents.Import "c:\CodeFile.bas"

Application.Run "KickStart"

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
oups.com...
I have a Module called "CodeFile.bas" which i Share amongst several
workbooks - It has a method called KickStart()

I want to do something like the following:

Private Sub Workbook_Open()

Me.VBProject.VBComponents.import "c:\CodeFile.bas"

Call KickStart()

End Sub


i.e. Import the code file and then subsequently call one of its
methods.

Any ideas how I could achieve this effect.

Dickster