after macro finish Word 2003 crash

K

Kenny

I have template with macro. Macro make array with filenames of all files .doc
from folder and then open every file, scan all paragraphs in file and read
style name. Then close file. If I run macro from VBA it works OK. If I start
macro from Word (I made button for it in template), sometimes at the end I
recieve two opened windows: one window with template (and that what I
waiting) and second window. When I close this second window - Word crash. It
looks like some thread of Word was not closed in time.

Dim iCounter As Integer, FileList() As String
Dim strFile As String, strPathToUse As String
Dim iFileIndex As Integer, objSrcDoc As Document
Dim objPar As Paragraph, sStyleName As String
iCounter = 0

On Error Resume Next
strPathToUse = "C:\Test"
strFile = Dir$(strPathToUse & Application.PathSeparator & "*.doc")
Do While strFile <> "" 'populate array with filenames
ReDim Preserve FileList(iCounter)
FileList(iCounter) = strFile
strFile = Dir$
iCounter = iCounter + 1
Loop
For iFileIndex = 0 To UBound(FileList)
strFile = strPathToUse & Application.PathSeparator & FileList(iFileIndex)
Set objSrcDoc = Documents.Open(strFile)
For Each objPar In objSrcDoc.Paragraphs
sStyleName = objPar.Style
Next objPar
objSrcDoc.Close wdDoNotSaveChanges
Set objSrcDoc = Nothing
Next iFileIndex
 
K

Kenny

Thank you, Jonathan. Article, you reference to, is very usefull. But I think
I solve problem: I uncheck (Tools/Options/View Windows in Taskbar). It looks
like solve my problem. I am testing now. This error was not always, that is
why I am not sure yet, so now I testing. If I'll not success, I'll try to do
step by step as it is written in these article. Thank you. Sorry for my
English.
 

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