visual Basic and excel
visual Basic and excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: visual Basic and excel

  1. #1
    New Member
    Join Date
    Feb 2002
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Does anyone know how to run an excel macro from visual basic? I have a lot of macros I want to use in a program I'm writing, and I can't figure out how to run the macros outside of Excel.

    For instance: I want to push a button in a visual basic 6.0 project, then excel would open and the macro would run.

    Thanks for any help

    Shawn

  2. #2
    Board Regular
    Join Date
    Feb 2002
    Location
    Richland, Washington
    Posts
    91
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Shawn -
    I'm guessing that working out of pure Visual Basic isn't that different from cross-application VBA. Here's an example of code I would use to open Excel from Word:

    Sub excelsession()
    Dim xlapp As Excel.Application
    'start excel...
    Set xlapp = CreateObject("Excel.Application")
    'now let's see it...
    xlapp.Visible = True
    'Add a workbook...
    xlapp.Application.Workbooks.Add
    'or, open a specific workbook..
    xlapp.Workbooks.Open "test.xls"
    End Sub

    For this to work, one must first load the Excel object models into your active library.

    I hope that gives you something to start with. Good Luck.
    Tom

  3. #3
    New Member
    Join Date
    Feb 2002
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thank you for the quick answer!

    Is there any place i could go to figure out how to work objects??? I think this is where I'm getting hung up.

    Shawn

  4. #4
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    On 2002-02-18 16:24, srv656s wrote:
    Thank you for the quick answer!

    Is there any place i could go to figure out how to work objects??? I think this is where I'm getting hung up.

    Shawn
    Hi Shawn, in order to run macros from the excel object just reference like;

    'Run the "ExcelMacroTest" procedure stored in the workbook
    xlapp.Application.Run "YourNameOfTheMacroToRun"


    HTH

    Ivan

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com