Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Why BuiltInDocumentProperties crashes Word?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lauro - 08 Aug 2005 12:49 GMT
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
Helmut Weber - 08 Aug 2005 16:08 GMT
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"
Lauro - 09 Aug 2005 16:26 GMT
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

>Hi Lauro,
>
[quoted text clipped - 9 lines]
>Win XP, Office 2003
>"red.sys" & Chr$(64) & "t-online.de"
Lauro - 09 Aug 2005 17:14 GMT
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

>Hi Helmut,
>
[quoted text clipped - 36 lines]
>>Win XP, Office 2003
>>"red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 09 Aug 2005 20:36 GMT
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
Lauro - 10 Aug 2005 16:05 GMT
Thanks for the help

Lauro

>Hi Lauro,
>
[quoted text clipped - 13 lines]
>"red.sys" & chr$(64) & "t-online.de"
>Win XP, Office 2003
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.