[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Excel automation (inserting macros programmatically)

Posted on 2006-04-12
2
Medium Priority
?
403 Views
Last Modified: 2010-04-07
Hello,

I wrote an application a while ago that creates reports in excel programatically using the Excel Object Library. At the time of development, I had Windows 2000 with Office 2000. I tested this on a machine with Windows XP and Office 2000 and it worked.

Now I have a machine with Windows XP and Office 2003. The application now generates an error: "Error 1004: Programmatic access to Visual Basic is not trusted". This, of course, happens on the line that tries to add a VBA macro as follows:

   Dim str As String
   Dim eCM As VBIDE.CodeModule
   Dim eVBC As VBIDE.VBComponent
   Set eVBC = eWB.VBProject.VBComponents.Add(vbext_ct_StdModule) ' Error here
   eVBC.Name = "mdlAudioBee"
   str = "Some Macro Text"
   eVBC.CodeModule.InsertLines 1, str

I have already set the lowest possible value for Excel > Tools > Macros > Security > Low and have also disabled my AntiVirus program (Norton).

What else do I need to do to allow the above operation?

Thanks,

Khan
0
Comment
Question by:raheelasadkhan
2 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 2000 total points
ID: 16439450
0
 

Author Comment

by:raheelasadkhan
ID: 16445989
Worked nicely. Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 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