I am attempting to adjust working code from early binding to late binding to avoid issues with users with different reference versions or missing reference issues. Specifically avoiding early binding for the Microsoft Word reference.
Per the below code, I am using Microsoft Excel to create a Microsoft Word object and open word documents for processing. I changed the variables to objects, but get hung up on --> Set wrdDocument = wrdApplication.Documents.Open(strPath) where it opens word but then hangs up, and advises it is waiting on a resource to complete an action.
What do I need to do to get this to work via late binding? I tried adding the value without setting it, but an unsure what needs to happen. I am sure it has something to do with not needing to set the document the same with a variable, but I am not sure how...
Any help is greatly appreciated!
Function AddRemoveWatermark()
'Word Variables
Dim wrdApplication As Object
Dim wrdDocument As Object
Set wrdApplication = CreateObject("Word.Application")
Dim strDocumentName As String
Dim strPath As String
Dim strBBPath As String
Dim lngCount As Long
Dim fso As Object
strBBPath = "C:\Users\" & (Environ$("Username")) & "\AppData\Roaming\Microsoft\Document Building Blocks\1033\" & lngMicrosoftVersion & "\Built-In Building Blocks.dotx"
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the file dialog
With Application.FileDialog(1) 'msoFileDialogOpen
.AllowMultiSelect = True
.Show
'Set wrdApplication = New Word.Application
AddRemoveWatermark = .SelectedItems.Count
' Display paths of each file selected
For lngCount = 1 To .SelectedItems.Count
strPath = .SelectedItems(lngCount)
Set wrdDocument = wrdApplication.Documents.Open(strPath)
strDocumentName = wrdDocument.FullName 'Record the document name
wrdApplication.Templates.LoadBuildingBlocks
Next lngCount
End With
End Sub