Why "User-defined type not defined"

S

Shatin

I got the following lines in my macro:

Dim VBCodeMod As CodeModule
Dim LineNum As Long

ActiveWorkbook.VBProject.VBComponents.Add vbext_ct_StdModule
Set VBCodeMod = Application.VBE.CodePanes(1).CodeModule

I think I copied those lines from the Pearson site. When I run the
macro from my personal.xls file, the macro runs without any problem.
However, when I copy the macro to a new file in the document folder,
the line "VBCodeMod As CodeModule" is highlighted and this error msg
appears:

Compile error:
User-defined typ not defined

Can someone please tell me what this error is? And why this error
since the macro runs problem free from the personal.xls?

TIA.
 
J

Jan Karel Pieterse

Hi Shatin,
the line "VBCodeMod As CodeModule" is highlighted and this error msg
appears:

Compile error:
User-defined typ not defined

Can someone please tell me what this error is? And why this error
since the macro runs problem free from the personal.xls?

You need a reference to the VBE Extensibilty library (Tools, References
from within the VBE)

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com
 
P

papou

Hello Shatin
Add a reference to Microsoft Visual Basic 6.0 Extensibility
HTH
Regards
Pascal
 
B

Bob Phillips

Shatin,

The reference to set is called
Microsoft Visual Basic for Applications Extensibility n.n
where n.n is a version number.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top