Why BuiltInDocumentProperties crashes Word?

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
 
H

Helmut Weber

Hi Lauro,

at a long shot,
wasn't it that in case of late binding
the constants like wdPropertyTemplate are unknown?
How about trying 6 instead of wdPropertyTemplate?


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
L

Lauro

Hi Helmut,

I have tried a very simple routine from Access

Public Sub pp()
Dim objWordApp As Object
Dim objWordDoc As Object

Set objWordApp = GetObject(, "Word.Application")
For Each objWordDoc In objWordApp.Documents
MsgBox objWordDoc.BuiltInDocumentProperties(6) & " " & _
objWordDoc.Name
Next
End Sub

And also this one crashes Word.

But I noticed that the crash happens only on a my particular document.

I've Tried to open this Document alone in Word and click on
File|Properties and strange enough also just in Word without any VBA
when I click OK sometime (not always) Word crashes.

It's just a Word Document, not an atomic bomb.

Greeting from Rome, Lauro
 
L

Lauro

Hi, Helmut

the mistery continues...

I tried to open the Culprit Document with Word on another computer. It
still crashes Word when I do File|Properties and then OK.
I tried with a similar Document (based on the same Template) and is
OK. Both documents are based on a Template not present in the
computer.

The crash happens only if the Culprit Document is the only one opened
in Word.

Do you think that that in someway that document got corrupted and I
don't have to warry with the others?

Thanks, Lauro
 
H

Helmut Weber

Hi Lauro,

very likely.

I think, I've read about a very basic way to test for corruption.
Delete all of the doc and try

msgbox Len(ActiveDocument.Range)

If greater than 1 then corrupted, probably.

Gruß

Helmut Weber, MVP WordVBA

"red.sys" & chr$(64) & "t-online.de"
Win XP, Office 2003
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top