Thank you very much for your help. I am getting an error message at the line
"Dim fDialog as FileDialog." The error says "Compile Error. User-defined type
not defined." Do you know why I'm getting an error and how I can fix it?
Thanks.
There should not be a period after FileDialog
If that doesn't fix it, use the following less elegant folder selection
routine
Sub PrintHeadings()
Dim para As Paragraph, rng As Range
Dim DocA As Document, DocB As Document
Dim iLevel As Integer, iMaxLevel As Integer
Dim myFile As String
Dim PathToUse As String
Dim MyDoc As Document
Dim iFld As Integer
' Get the folder containing the files
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
'Close any documents that may be open
If Documents.Count > 0 Then
Documents.Close Savechanges:=wdPromptToSaveChanges
End If
FirstLoop = True
If Left(PathToUse, 1) = Chr(34) Then
PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If
myFile = Dir$(PathToUse & "*.doc")
If Documents.Count > 0 Then 'close any open documents
Documents.Close Savechanges:=wdPromptToSaveChanges
End If
' Ask for max level
iMaxLevel = InputBox("Enter maximum level for Heading style.")
If iMaxLevel = 0 Then Exit Sub
StatusBar = "Printing headings. Please wait..."
'Open the document to collect the data
Set DocB = Word.Documents.Add '(DocA.AttachedTemplate.name)
' Set extra wide page margins
With DocB.PageSetup
.TopMargin = InchesToPoints(0.25)
.BottomMargin = InchesToPoints(0.25)
.LeftMargin = InchesToPoints(0.25)
.RightMargin = InchesToPoints(0.25)
End With
While myFile <> ""
'open the document for processing
Set MyDoc = Documents.Open(PathToUse & myFile)
Set DocA = ActiveDocument
Set rng = DocB.Range
For Each para In DocA.Paragraphs
DoEvents
iLevel = 0
' Check for Heading style
If para.Format.Style Like "Heading [0-9]" Then
iLevel = Val(Mid(para.Format.Style, 8))
' Check for acceptable level
If iLevel > 0 And iLevel <= iMaxLevel Then
rng.Collapse wdCollapseEnd
rng.Text = String(iLevel - 1, vbTab) & _
Format(iLevel) & ") " & para.Range.Text
End If
End If
Next para
' Delete any annoying page breaks
rng = Replace(rng, "^m", "")
DocA.Close Savechanges:=wdDoNotSaveChanges
Set DocA = Nothing
GetNextDoc:
myFile = Dir$()
Wend
'Save target doc
DocB.Save
Set DocB = Nothing
' Tell user when done
MsgBox "Done creating new document with headings only."
End Sub
> Thank you very much for your help. I am getting an error message at
> the line "Dim fDialog as FileDialog." The error says "Compile Error.
[quoted text clipped - 187 lines]
>>>
>>> End Sub
jkmar5 - 19 Feb 2008 13:39 GMT
Wow. This macro works like a dream. Thank you, thank you, thank you!
> There should not be a period after FileDialog
> If that doesn't fix it, use the following less elegant folder selection
[quoted text clipped - 282 lines]
> >>>
> >>> End Sub
Graham Mayor - 19 Feb 2008 15:25 GMT
You are welcome :)

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Wow. This macro works like a dream. Thank you, thank you, thank you!
>
[quoted text clipped - 284 lines]
>>>>>
>>>>> End Sub