Hello,
I have an excel spreadsheet with multiple named fields across multiple sheets. I am generating a Word Document that is populated by embedded tables linked back to the named fields. However, I cannot find a way to add the field name to the properties of the object, so it outputs the whole sheet as the embedded object for each named field. In my commented out code, I have tried to add the Field Name as a string to the file path in the format that the field name is referenced if I was to do it manually in the field code but the program does not recognize it. Is there a good way to do this?
Your help is much appreciated.
Thanks, Joe
I have an excel spreadsheet with multiple named fields across multiple sheets. I am generating a Word Document that is populated by embedded tables linked back to the named fields. However, I cannot find a way to add the field name to the properties of the object, so it outputs the whole sheet as the embedded object for each named field. In my commented out code, I have tried to add the Field Name as a string to the file path in the format that the field name is referenced if I was to do it manually in the field code but the program does not recognize it. Is there a good way to do this?
Code:
Function CreateBOE()
Dim strFilePath As String
strFilePath = ThisWorkbook.FullName
Set wb = ActiveWorkbook
Dim objWord
Dim objDoc
Dim objSelection
Dim ws As Worksheet
Dim nm As Name
Dim i As Integer
Dim title As String
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
objWord.Visible = True
With objDoc
For Each ws In Worksheets
i = i + 1
For Each nm In ws.Names
title = nm.Name
InsertEmbed i, title, objDoc, strFilePath
Next
Next
End With
End Function
Sub InsertEmbed(a, title, objDoc, strFilePath)
objDoc.InlineShapes.AddOLEObject ClassType:="Excel.Sheet.12", Filename _
:=strFilePath, LinkToFile:=True, DisplayAsIcon:=False
'objDoc.InlineShapes.AddOLEObject ClassType:="Excel.Sheet.12", Filename _
:=strFilePath & " " & title, LinkToFile:=True, DisplayAsIcon:=False
End Sub
Your help is much appreciated.
Thanks, Joe