Solved

VBA to Import Module

Posted on 2008-10-15
5
1,255 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:MikeMcEvoy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 22724281
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
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 22724307
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
 
LVL 2

Author Comment

by:MikeMcEvoy
ID: 22724481
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
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 22724719
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
 
LVL 2

Author Comment

by:MikeMcEvoy
ID: 22724769
Perfect Thanks!  
Saurabh thanks for your suggestion as well.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question