Solved

Exec Excel Macro from VB6

Posted on 2000-03-07
3
507 Views
Last Modified: 2008-02-01
Is there a way to kick off a
macro resident in a Excel 2000 spreadsheet (other than the auto ones) from a visual basic .exe?

Thanks a bunch.
0
Comment
Question by:jogmen
[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
3 Comments
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2593270
I'm a little fuzzy on this (it has been a while . . .) but I think it goes like this.  Declare and instantiate a reference to an Excel object, then invoke the procedure with the .Run method:

Dim objExcel as object
Set objExcel = GetObject(, "Excel.Application")
objExcel.Run("sub as string", arg1, arg2)

You need to reference the Excel library.

Wes

0
 
LVL 3

Accepted Solution

by:
MTroutwine earned 50 total points
ID: 2593868
Here is what I normally use:


    ' Declare Excel object:
    Dim objApp As Excel.Application
   
    ' Instantiate the Excel object:
    Set objApp = New Excel.Application
       
    With objApp
        ' Open the spreadsheet:
        .Workbooks.Open "D:\ExcelSpreadsheetName.xls"
        ' Make Excel visible to the user (the default is False):
        .Visible = True
        ' Runt the macro (This supports up to 30 arguments):
        .Run "MacroName"
    End With
   
    ' Do whatever you are going to do...
   
    ' If you want to end Excel programmatically and save changes to do this:
    ' Close has three optional parameters here they are in order:
    ' 1) SaveChanges: Boolean - True = yes save the changes
    '                           False = no don't save the changes
    ' 2) Filename: String - A new file name (if you don't want to save as the old file).
    ' 3) Routeworkbook: Boolean - I have never used this, has something to do with sending
    '                             the workbook to another user.
    objApp.Workbooks("ExcelSpreadsheetName.xls").Close True

:>)
0
 
LVL 3

Expert Comment

by:MTroutwine
ID: 2593871
One thing as mentioned by wesleystewart, you will need to add a reference to the following:

Microsoft Excel 9.0 Object Library
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

688 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