Execute an excel from vb and execute a macro that is in this excel file

Posted on 2006-04-21
Last Modified: 2010-05-01
Hello, I´m creting a little application to control another excel application.

I have to open a determinate excel file, and I have to pass to a textbox some parameters, after this I will have to execute the event of a button.

I guess that it´s possible, isn´t it¿?
Question by:1469
    LVL 44

    Accepted Solution

    Hello 1469,

    this is a great place to start

    be sure to add a reference to excel under your projects | references in VB
    Dim oXLApp As Excel.Application
    Dim oXLBook As Excel.Workbook
    Dim oXLSheet As Excel.Worksheet

    'this will open the workbook
      Set oXLApp = New Excel.Application
      Set oXLBook = oXLApp.Workbooks.Open("c:\my folder\my workbook.xls")
      Set oXLSheet = oXLBook.Sheets(1)
      oXLApp.Visible = True
    'now pass some data to the sheet 1
      oXLSheet.Cells(1, 1) = "hello there" 'cell A1
      oXLSheet.Cells(2, 1) = "hello there" 'cell A2
    'now execute a macro
      oXLApp.Run "myMacroName" [, "Arg1"][, "Arg2"] 'you can add arguments here or only call the macro by name


    hope this helps a bit

    Author Comment

    I want to pass some text to a textbox that is into a frame
    LVL 44

    Expert Comment

    a frame, is this a webpage or a vb application?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    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…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now