VBA to Import Module

Hello,

I just need a simple vba script that will import module "C:\Documents and Settings\mm31896\Desktop\Module4.bas".

I've tried a few examples that I found by searching previous answers but they all seem to kick out run time errors. Any help would be greatly appreciated.
'This is an example of attempt that kicks out a runtime error.
 
Sub AddBasFile()
ThisWorkbook.VBProject.VBComponents.Import _
Filename:="C:\Documents and Settings\mm31896\Desktop\Module4.bas"
End Sub

Open in new window

LVL 2
MikeMcEvoyAsked:
Who is Participating?
 
zorvek (Kevin Jones)ConsultantCommented:
I can import the module without issue.

Have you enabled access to the VBA project? The option is set on the Trusted Publishers tab of the Security dialog (Tools->Macros->Security, "Trust access to Visual Basic Project").

Kevin



0
 
Saurabh Singh TeotiaCommented:
I believe this is what you are looking for a good read about how to the same...

http://www.cpearson.com/Excel/vbe.aspx

Saurabh...
0
 
zorvek (Kevin Jones)ConsultantCommented:
There is probably something wrong with the import file. Can you post it? Do you already have a module with the same name? What is the error?

Kevin
0
 
MikeMcEvoyAuthor Commented:
The import file seems to be ok.  It actually contains code that you helped me with a few days ago (It's attached).
The Error is "Method VBProject' of object'_Workbook' failed"
I looked at Chip Pearson's site and have not been able to figure it out.

Module4.txt
0
 
MikeMcEvoyAuthor Commented:
Perfect Thanks!  
Saurabh thanks for your suggestion as well.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.