+ Reply to Thread
Results 1 to 2 of 2

Can't get Word to run an Excel macro

  1. #1
    Registered User
    Join Date
    07-24-2017
    Location
    Eugene, OR USA
    MS-Off Ver
    MS Office 2010
    Posts
    2

    Question Can't get Word to run an Excel macro

    I'm trying to figure out why my Word 2010 VBA will not run an Excel macro from within a Word macro.
    I can successfully do the reverse and run a Word macro from an Excel macro, but get an error when trying to
    do it the other way around.

    The working macros and their non-working versions are below. I'm sure I'm missing something simple, but it eludes me so far. Thanks for any help!
    -----------------

    These two macros WORKED to pass variables from the Excel macro into theWord macro:

    Excel macro to run the TestGetVarFromXL macro:

    '***********************************************
    Sub RunTestGetVarFromXL()
    'This worked.
    '~~> Establish an Word application object
    On Error Resume Next
    Set wrdApp = GetObject(, "Word.Application")

    If Err.Number <> 0 Then
    Set wrdApp = CreateObject("Word.Application")
    End If
    Err.Clear
    On Error GoTo 0

    'Test assigning variables:
    CourseStartRow = "44"
    CourseEndRow = "54"
    CourseTitle = "MS Word 2016"

    'Using Call command to run this word macro and pass these variables into it:
    Call wrdApp.Run("TestGetVarFromXL", CourseStartRow, CourseEndRow, CourseTitle) '

    End Sub
    '********************************************************
    ----------------------------------------------------------------------------
    Word macro to receive variables from Excel macro that calls it:
    '*****************************************************
    Sub TestGetVarFromXL(CourseStartRow, CourseEndRow, CourseTitle)
    'This Worked to receive these variable data from Excel macro: RunTestGetVarFromXL

    MsgBox ("From Word TestGetVarFromXL macro:" & Chr(13) & Chr(13) & _
    "CourseStartRow = " & CourseStartRow & Chr(13) & Chr(13) & _
    "CourseEndRow = " & CourseEndRow & Chr(13) & Chr(13) & _
    "CourseTitle = " & CourseTitle)

    End Sub
    '***************************************************
    ===================================================================
    =======================================================================
    *** These two macros below did NOT Work**********************
    They are similar to the above macros but changed to do the reverse of calling an Excel macro from Word.

    Get the error message:
    "Run-time error '1004': Cannot run the macro 'RunTestGetVarFromWord". The macro may not be available in this workbook or all macros may be disabled":

    Word macro to run the TestGetVarFromWord macro:
    '***************************
    Sub RunTestGetVarFromWord()
    'This did NOT work, currently getting error message:
    '"Run-time error '1004': Cannot run the macro 'TestGetVarFromWord". The macro may
    'not be available in this workbook or all macros may be disabled"

    '~~> Establish an Excel application object
    On Error Resume Next
    Set xlApp = GetObject(, "Excel.Application")

    If Err.Number <> 0 Then
    Set xlApp = CreateObject("Excel.Application")
    End If
    Err.Clear
    On Error GoTo 0

    'Test assigning variables to pass:
    CourseTitle = "MS Word 2016"
    CourseStartRow = "44"
    CourseEndRow = "54"

    'Run the word macro and pass these variables into it:
    Call xlApp.Run("TestGetVarFromWord", CourseStartRow, CourseEndRow, CourseTitle) '

    End Sub
    '*********************************

    Excel macro to receive variables from Word macro that calls it:
    '**************************************************
    Sub TestGetVarFromWord(CourseStartRow, CourseEndRow, CourseTitle)
    'This did NOT work (was not called successfully from the Word macro: RunTestGetVarFromWord.

    MsgBox ("From Excel TestGetVarFromWord macro:" & Chr(13) & Chr(13) & _
    "CourseStartRow = " & CourseStartRow & Chr(13) & Chr(13) & _
    "CourseEndRow = " & CourseEndRow & Chr(13) & Chr(13) & _
    "CourseTitle = " & CourseTitle)

    End Sub
    '*****************************

  2. #2
    Registered User
    Join Date
    07-24-2017
    Location
    Eugene, OR USA
    MS-Off Ver
    MS Office 2010
    Posts
    2

    Re: Can't get Word to run an Excel macro

    Problem solved: the command calling the Excel macro needed to also include the VBAProject name added to the beginning of the macro name (including the ! character):
    ...
    Call xlApp.Run("Personal.xlsb!TestGetVarFromWord", CourseStartRow, CourseEndRow, CourseTitle)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel to Word macro doesn't work on Word 2013 if sheet is hidden (works fine on 2010)
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2015, 04:37 AM
  2. error when running MS Word macro commands in Excel macro
    By bsapaka in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2014, 01:30 PM
  3. [SOLVED] Excel macro- Find replace an itallic font word with a regular word?
    By thisisaboutwork in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2013, 01:48 PM
  4. Need help with Excel-to-Word find and replace macro based on word filename
    By EnterTheSerpent in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2013, 12:48 PM
  5. [SOLVED] Need syntax for RUNning a Word macro with an argument, called from an Excel macro
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-06-2006, 02:45 PM
  6. WORD-DELIMITED string vba macro for excel/word
    By jackal2k6 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2005, 12:35 PM
  7. Excel Macro call Word Macro with Parameters
    By Bill Sturdevant in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-25-2005, 01:05 PM

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