Running Excel macros from Word

M

Miguel Velez

I got a Word document with an inbedded Excel spreadsheet.
I want to run a macro that reads a text file and updates
the data contained in the inbedded Excel spreadsheet.

I've written an Excel macro (which is contained within the
inbedded Excel spreadsheet) that does the updating. I now
need to write a Word macro that will run this Excel macro.

Is there any way I can do that?

Or is there another approach?

Miguel
 
P

Perry

Can be done.

In Excel workbook "c:\temp\RunMacro.xls" I've entered following macro
in ThisWorkbook module:

Public Sub MyMacro(SomeString As String)
MsgBox SomeString
End Sub

The above workbook is embedded in a Word document as an Inlineshape.
Macro in a standard module in same Word document:
Sub Test()
Dim xl As Object
With ActiveDocument.InlineShapes(1).OLEFormat
.Activate
Set xl = .Object
End With
xl.mymacro "Hello World"
Set xl = Nothing
End Sub

Krgrds,
Perry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top