Open Excel File embedded in Word Document from vba in Excel

JoeStellar

New Member
Joined
Mar 11, 2019
Messages
5
As the above title suggests I'm tring to open an Excel document that is embedded in a Word document from within my Excel document using VBA. This is the first time I couldn't find a pre-existing answer to my problem.

The reason I'm trying to do this, in case someone has a better solution, is because our official test specification is a Word Document and embedded in this word document is an Excel document that contains the exact data I need to compare data that I have collected to. The test specification will be updated from time to time, so I can't just save the embedded Excel file locally and use it as a reference. I have my whole process automated and just have this final step to complete.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
If it's just data, why not use a Word table? Alternatively, you could have your Excel data in a separate file that your document links to, thus being able to display the data in Word whilst having the flexibility of not having to open the Word document for your analyses.
 
Upvote 0
Hi,
Use this code as a template to edit sheet of Excel's workbook which is embedded into a Word document:
Rich (BB code):
Sub EditWbEmbeddedIntoDocument()
 
  ' Change to suit
  Const MyDoc = "D:\Tmp\MyDocument.docx"
 
  ' Variables
  Dim objWord As Object, objDoc As Object
  Dim objWb As Workbook
 
  ' Get Word appplication
  On Error Resume Next
  Set objWord = GetObject(, "word.application")
  If Err Then
    Set objWord = CreateObject("word.application")
    objWord.Visible = True
  End If
  On Error GoTo 0
 
  ' Get Word Document
  Set objDoc = objWord.Documents.Open(MyDoc)
 
  ' Get Workbook
  With objDoc.InlineShapes(1).OLEFormat
    .Activate
    Set objWb = .Object
  End With
 
  ' Change Sheets(1)
  objWb.Windows(1).WindowState = xlMaximized
  objWb.Sheets(1).Range("A2") = Now
 
End Sub
Regards
 
Upvote 1

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top