+ Reply to Thread
Results 1 to 2 of 2

passing arguments from an excel macro to a word macro

  1. #1
    KWE39
    Guest

    passing arguments from an excel macro to a word macro

    I have an excel macro that opens a word document through a shell command.
    The word document also has macros associated with it that are triggered on
    the "open" event. What is the best way to pass values in my excel macro to
    my word macro?

  2. #2
    Henry
    Guest

    Re: passing arguments from an excel macro to a word macro

    KWE,
    Why do you need a shell command?
    Instead, open Word (and the Word Doc) from Excel VBA.
    That way, you can keep all your macro commands in Excel VBA and have no need
    to pass variables to Word.

    Dim appWD As Word.Application
    Set appWD = CreateObject("Word.Application.9") 'For Word 2K. For Word XP
    use "Word.Application.10" etc.
    appWD.Visible = False 'If you want to hide word window and have it
    working in the background.
    appWD.ChangeFileOpenDirectory "C:\directory where your word Doc is"
    'Word looks here for file.
    appWD.Documents.Open Filename:="Your doc's name", ConfirmConversions:=False,
    ReadOnly:=True, _
    AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
    Revert:=False, _
    WritePasswordDocument:="", WritePasswordTemplate:="",
    Format:=wdOpenFormatAuto 'Open doc



    You can manipulate the word doc from here using Word VBA

    E.g. To put today's date in a formfield bookmarked as Date

    appWD.ActiveDocument.FormFields("Date").Select
    appWD.ActiveDocument.FormFields("Date").Result = Date

    To close Word from Excel VBA use

    appWD.DisplayAlerts = wdAlertsNone 'Turn off alerts if you don't want the
    "Save Document?" box to show.
    appWD.Quit SaveChanges:=False 'Quit word

    Henry


    "KWE39" <[email protected]> wrote in message
    news:[email protected]...
    >I have an excel macro that opens a word document through a shell command.
    > The word document also has macros associated with it that are triggered on
    > the "open" event. What is the best way to pass values in my excel macro
    > to
    > my word macro?




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1