0

I have a piece of code in excel that modifies an embedded word document (displayed as icon) and saves it to a path. I have to convert it to late binding because of compatibility issues. How do i do it? What do I have to change? here is part of my code, as an example

Function Sport()

Dim wd As Word.Application
Dim doc As Word.Document

Dim ole As OLEObject
Dim EmbededFile As String

Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet with the embedded file")

' Change to suit your needs, or build with code
EmbededFile = ThisWorkbook.path & "\Stuff.doc"

Set ole = ws.OLEObjects("Object")
ole.Activate
'ole.Verb Verb:=xlOpen
Set wd = ole.Object.Application
With wd.ActiveDocument
    .SaveAs EmbededFile, Word.wdFormatDocumentDefault
    .Close
End With
Set doc = wd.Documents.Open(EmbededFile)

'' do stuff


wd.Activate
doc.Close
wd.Quit

Sport = 3
End Function

thanks in advance for the help

  • 2
    Dim wd As Word.Application -> Dim wd As Object ... etc ... –  Jan 08 '18 at 17:00
  • Can you elaborate on *compatibility issues*? Have you run into issues caused by different users running different versions of Word? – David Rushton Jan 08 '18 at 17:06
  • Yes I used Word object library 15.0 in Excel 2016 and it didn't work in Excel 2003 (the latest Obj Lib was 11.0). It said missing Word object library 15.0 –  Jan 08 '18 at 17:08
  • Note that the 2003 and 2016 object models are potentially quite different; if your code uses features that didn't exist in the 2003 object model, expect things to blow up at run-time with error 438 "Object doesn't support this property or method". Otherwise, just remove the reference, make sure you have `Option Explicit` at the top of every single module, and replace Word types with `Object`, remove all `Word` qualifiers, and define your own constants (e.g. `wsFormatDocumentDefault`) - rinse & repeat until the project compiles again (Alt+D,ENTER). Harder if you don't have `Option Explicit` on. – Mathieu Guindon Jan 08 '18 at 17:23
  • how do I redefine the `wsFormatDocumentDefault` as constant? and what do I substitute `Word` with? (sorry I'm really ignorant in vba) –  Jan 08 '18 at 17:52

0 Answers0