running excel macro outside excel
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: running excel macro outside excel

  1. #1
    Join Date
    Jan 2003
    Posts
    195

    running excel macro outside excel

    guys

    how do i run a macro outside excel using vbscript? thanks in advance
    Share on Google+

  2. #2
    Join Date
    Oct 2005
    Location
    England
    Posts
    803

    Re: running excel macro outside excel

    open a text editor copy your code in and save it as a .vbs file.

    as a simple test write this line in the .vbs file

    Code:
    msgbox "VBS"
    To run it, double click on the .vbs file

    if you have used any objects you will have to create them manually.

    Rich
    Share on Google+

  3. #3
    Join Date
    Jan 2003
    Posts
    195

    Re: running excel macro outside excel

    guys

    i finally found how to call a macro outside excel. Now the problem is how to pass dynamic values .

    sample code follows,

    VBScript

    Code:
    Option Explicit
    
          Private Sub Command1_Click()
           Dim oExcelApp As Object
    
           ' Create a reference to the currently running excel application
           Set oExcelApp = GetObject(, "Excel.application")
           ' Make the Excel Application Visible.
           oExcelApp.Visible = True
           ' Run the excel procedure
           oExcelApp.run "proc", "David", 30
          End Sub
    
    
    
    Excel macro
    
    Sub Proc(sParam1 As String, iParam2 As Integer)
            MsgBox sParam1 & " is " & iParam2 & " Years Old"
          End Sub
    Thanks
    Last edited by PeejAvery; November 22nd, 2011 at 02:24 PM. Reason: Added code tags
    Share on Google+

  4. #4
    Join Date
    Jan 2003
    Posts
    195

    Re: running excel macro outside excel

    Thnx guys

    found out how to do it
    Share on Google+

  5. #5
    Join Date
    Oct 2011
    Posts
    1

    Re: running excel macro outside excel

    Hi,

    though it's VERY old thread, I'd like to get back to it:

    vbnov, I am having exactly the same problem. You say you solved it.

    Could you please let me know how you did it?

    Thanks a lot!
    James
    Share on Google+

  6. #6
    Join Date
    Nov 2011
    Posts
    9

    Re: running excel macro outside excel

    It's an interesting concept.
    I'd love to be able to call macros from a closed Excel file, but I don't think that's possible.
    Share on Google+

  7. #7
    Join Date
    May 2012
    Posts
    1

    Re: running excel macro outside excel

    For anyone still wondering.. I was able to use the code from vbnov. It worked exactly as stated.

    Script:
    ExcelApp.Run "TestModule.Start", "TestParam1", "TestParam2"

    Module:
    Sub Start (TestVal as String, TestVal2 as String)

    End Sub
    Share on Google+

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,092

    Re: running excel macro outside excel

    Due to the fact that this thread keeps being revived, I decided to close it. Please create a new thread and reference this thread.
    Share on Google+

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center