I have a very simple Word sub in a dotm template:
Sub YHelloThar(msg As String)
MsgBox (msg)
End Sub
I then have an Excel sub:
Sub CallWordSub()
Dim wdApp As Word.Application
Dim newDoc As Word.Document
'Word template location
strFile = "C:\Some\Folder\MyWordDoc.dotm"
'Get or create Word application
Set wdApp = GetObject(, "Word.Application")
If wdApp Is Nothing Then
Set wdApp = CreateObject("Word.Application")
End If
'Create new Word doc from template
Set newDoc= wdApp.Documents.Add(strFile)
'Call the YHelloThar sub from the word doc
Call wdApp.Run(strFile & "!YHelloThar", "Hello")
End If
End Sub
The last line gives me "Run-time Error '438': Object does not support this property or method."
I'm not sure what I am doing wrong - everything I have looked up indicates this is the proper way to do call subs from different applications.
Furthermore, if I change the last line to be a parameter-less call it suddenly works correctly.