Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Macros in VB

Status
Not open for further replies.

schnabs

Technical User
Jan 21, 2009
50
0
0
Hello,
I am using Visual Basic 2008 to open an excel sheet. I want to run a macro from a separate sheet, as I don't want clients having access to running it, as well as most clients have macros disabled and it throws an error when they open it. Anyways, my code looks OK I think..

Dim oxl As Microsoft.Office.Interop.Excel.Application
Dim oxlbook As Microsoft.Office.Interop.Excel.Workbook
oxl = New Microsoft.Office.Interop.Excel.Application
oxlbook = oxl.Workbooks.Open("C:\Documents and Settings\Bob\Desktop\Book8.xls")
oxl.Visible = True
oxl.Run("C:\Documents and Settings\Bob\Desktop\Book5.xla!DelinqNormal()")

I have read around that when you automate Excel through VB, it doesn't load the add-ins required to run Macros. I cannot, however, find the code necessary to load the add-ins, or which ones to load. Any help would be great!
Thanks!
 
If the users have macros disable anyways, wouldn't it still fail if you tried to automate the macro from your application? You might think about porting the macro logic to your VB.Net app.
 
Well I guess I could do that. I was just trying to keep it separate, for what reason IDK. There wouldn't be any problem on the user end though, as once I run the macro, I would save the file separately, then post them to a website for them to view. They only need the end result. And I also wanted to know how to load them just for my own satisfaction. :)
 
Or, River, if you wouldn't mind helping with the basic code to run the macro from within my project, that would be great too.
 
Figured it out. I tried putting single quotes around the Book5, but I had to put it around the whole path.

oxl.Run("'C:\Documents and Settings\Bob\Desktop\Book5.xls'!DelinqNormal()")

Darned single quotes. Thanks River.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top