2

We have a standard form in MS Word to manually fill in details and launch a macro. This macro will open a MS Excel register to auto populate it from the fields in the Word document whilst doing other things.

The current solution has a keyboard shortcut for the macro in the Excel spreadsheet and the Word document macro sends the keys strokes to the opened Excel spreadsheet to launch the macro. This only works for a few people in the office.

Can I call my Excel macro directly from the Word macro while my Excel spreadsheet is in focus or is there a Windows setting that is blocking my send keys to launch the macro?

1
  • Could you show some code where it is failing? Does the Word macro have a reference to Excel? Commented Nov 10, 2011 at 23:41

1 Answer 1

4

This is just a hunch, but would it be possible to migrate the Excel macro from the Excel spreadsheet to the Word document? Then you could add a bit of code to launch the correct Excel spreadsheet and perform the necessary field manipulations. So, basically, let your Word document do all the work on the Excel spreadsheet.

Alternately, you could follow the procedure discussed here:

http://support.microsoft.com/kb/177760

Here is the relevant code listing:

 Sub XLTest()

     Dim XL as Object

     Set XL = CreateObject("Excel.Application")

     XL.Workbooks.Open "C:\My Documents\ExcelFile.xls"

     ' If there is more than one macro called TestMacro,
     ' the module name would be required as in
     '
     ' XL.Run "Module1.TestMacro"
     '
     ' to differentiate which routine is being called.
     '
     XL.Run "TestMacro"

End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately I have already tried this, the macro fails on a compile error for function "Cells()". I’m thinking this might be because it’s an MSword macro attempting to perform excel function.
jneasy, did you try the second solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.