[Webinar] Streamline your web hosting managementRegister Today


Running a Word Macro inside a VB Application

Posted on 1999-11-24
Medium Priority
Last Modified: 2010-05-02
I want to have a command button in my vb application, where i click on it and it opens up a common dialog box thats ok. The file i have selected in the cd box, is the file i want opened in Word and then run my macro on this.

How do I do this?
Question by:jonnygrant
  • 2

Author Comment

ID: 2231028
Adjusted points to 100

Accepted Solution

Juilette earned 300 total points
ID: 2231172
Shell "C:\Program Files\Microsoft Office\Office\WINWORD.EXE /mymacro", 1

Expert Comment

ID: 2231218
'use word object to run open a word doc and run a macro
'in references, make reference to word object

'<<<<  code for event opening word object and running macro >>>>
    Dim strInput As String     '<<<<  variable for macro name
    strInput = lstMacro.Text   '<<<<  in this example the name is pulled
                               '<<<<  from a list box (listbox text)

          Dim oWord As Object
          Set oWord = New Word.Application

          oWord.Visible = True   '<<<< make word visible (not needed unless you need visible)
      oWord.Documents.Open "c:\Your directory\Your SubDirectory\Your file.doc"
      oWord.Run strInput     '<<<< run your macro
     End If


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month9 days, 10 hours left to enroll

591 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