?
Solved

Exec Excel Macro from VB6

Posted on 2000-03-07
3
Medium Priority
?
510 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 200 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

Independent Software Vendors: 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 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