L
Lauro
I'm trying to populate an array fo string with the name of the file
based on "MyTemplate.dot" also if the reference to the template is
broken.
In the latter case AttachedTemplate is of no use because reports
always "normal.dot", so I used
BuiltInDocumentProperties(wdPropertyTemplate).
I use my code in Access to autamate Word, but, in a not consistent
manner, this code crashes Word when passing on
BuiltInDocumentProperties, Why?
Any suggestions?
Thanks, Lauro
'-- a global variable
gArrFilesOpen() as string
Function PopulateArray() As Long
'report -1 if an error occurs, otherwise the number of files found
Dim objWordApp As Object 'Word.Application -- early or late binding
Dim objWordDoc As Object ' Word.Document -- is the same
Dim lngNumFileOpen As Long
On Error GoTo Err_PopulateArray
lngNumFileOpen = 0
ReDim gArrFilesOpen(lngNumFileOpen)
Set objWordApp = GetObject(, "Word.Application")
For Each objWordDoc In objWordApp.Documents
If objWordDoc.BuiltInDocumentProperties( _
wdPropertyTemplate) = "MyTemplate.dot" Then
gArrFilesOpen(lngNumFileOpen) = objWordDoc.Name
lngNumFileOpen = lngNumFileOpen + 1
ReDim Preserve gArrFilesOpen(lngNumFileOpen)
End If
Next
PopulateArray = lngNumFileOpen
Exit_PopulateArray:
Set objWordApp = Nothing
Set objWordDoc = Nothing
Exit Function
Err_PopulateArray:
lngNumFileOpen = -1
Resume Exit_PopulateArray
End Function
based on "MyTemplate.dot" also if the reference to the template is
broken.
In the latter case AttachedTemplate is of no use because reports
always "normal.dot", so I used
BuiltInDocumentProperties(wdPropertyTemplate).
I use my code in Access to autamate Word, but, in a not consistent
manner, this code crashes Word when passing on
BuiltInDocumentProperties, Why?
Any suggestions?
Thanks, Lauro
'-- a global variable
gArrFilesOpen() as string
Function PopulateArray() As Long
'report -1 if an error occurs, otherwise the number of files found
Dim objWordApp As Object 'Word.Application -- early or late binding
Dim objWordDoc As Object ' Word.Document -- is the same
Dim lngNumFileOpen As Long
On Error GoTo Err_PopulateArray
lngNumFileOpen = 0
ReDim gArrFilesOpen(lngNumFileOpen)
Set objWordApp = GetObject(, "Word.Application")
For Each objWordDoc In objWordApp.Documents
If objWordDoc.BuiltInDocumentProperties( _
wdPropertyTemplate) = "MyTemplate.dot" Then
gArrFilesOpen(lngNumFileOpen) = objWordDoc.Name
lngNumFileOpen = lngNumFileOpen + 1
ReDim Preserve gArrFilesOpen(lngNumFileOpen)
End If
Next
PopulateArray = lngNumFileOpen
Exit_PopulateArray:
Set objWordApp = Nothing
Set objWordDoc = Nothing
Exit Function
Err_PopulateArray:
lngNumFileOpen = -1
Resume Exit_PopulateArray
End Function