Solved

VBA to Import Module

Posted on 2008-10-15
5
1,250 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
  • 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

803 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