Consulting

Results 1 to 2 of 2

Thread: Passing an Excel VBA variable to MS Word VBA

  1. #1
    VBAX Regular
    Joined
    May 2010
    Posts
    10
    Location

    Passing an Excel VBA variable to MS Word VBA

    Hi,

    I have a variable in excel vba and looking for passing the variable to MS word vba.

    Any steer in the right direction is more than welcomed.

    Thank you in advance

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]Sub TestPass()
    Dim Wd, Doc
    Set Wd = CreateObject("Word.application")
    Set Doc = Wd.documents.Open("C:\AAA\Doc1.doc")
    Wd.Visible = True
    Wd.Application.Run "Test", "Data to pass"
    Doc.Close
    Set Doc = Nothing
    Wd.Quit
    Set Wd = Nothing
    End Sub
    [/vba]

    In Word document
    [vba]
    Sub Test(MyData As String)
    MsgBox MyData
    End Sub

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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