Results 1 to 4 of 4

Thread: Execute Marco From Excel 97

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    7

    Question

    I have opened an excel file in my VB project and I want to excecute an existing macro in my workbook.

    Dim Classeur As Workbook

    Set Classeur = Workbooks.Open("d:\file.xls")
    Workbooks.Close

    have you an idea?

    Thanks

  2. #2
    New Member
    Join Date
    May 2000
    Posts
    6

    Cool

    Here :

    Open the workbook then press Alt-F8 or click Tools -> Macro -> Macros and highlight macro name and click Run button.

    [Edited by shinned on 05-30-2000 at 09:47 AM]
    Shinned
    Email : [email protected]
    Home : http://www.geocities.com/shinned

    VB Ver : 6.0

  3. #3
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    I think he is trying to run the macro automatically out of the VB project.

    In Excel, start the macro recorder, open the sheet with the macro, run the macro. Stop the macro recorder, and go look at the code generated for opening the sheet and running the macro.

    This is what I got:

    Code:
        Workbooks.Open FileName:="C:\My Documents\Test Macro.xls"
        Application.Run "'Test Macro.xls'!MoveEmail"

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    For Excel use the following:

    Code:
      Set xlApp = CreateObject("Excel.Application")
      xlApp.Visible = True
      DoEvents  'Pause until everything previously has been process
    '  PURPOSE:Technique to run a macro in another Microsoft Application
    '  Another technique would be sticking the pBrain macro into the "Open" event
      xlApp.Workbooks.Open FileName:=gstrTemplateDirectory & "FormatText.xls"
      xlApp.Run "FormatText.xls" & "!pBrain"

    For Word use the following:
    Code:
      Set xlApp = CreateObject("Word.Application")
      xlApp.Visible = True
      DoEvents  'Pause until everything previously has been process
    
    '  PURPOSE:Technique to run a macro in another Microsoft Application
    '  Another technique would be sticking the pBrain
    '  macro in "Macro.doc" into the "Open" event
      xlApp.Documents.Open FileName:=gstrTemplateDirectory & "Macro.doc", PasswordDocument:="Testing"
      
    ' PURPOSE: Call this macro
      xlApp.Run MacroName:="pBrain"
    Chemically Formulated As:
    Dr. Nitro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width