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
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