K
Krystal
Here is what I am trying to accomplish using Word 2007 and XP:
I want to create a TOC with the Title and Individual Section Page Counts
using separate Individual Files to look like this:
Section No. Title No. of Pages
200500 General Provisions 5
200505 Project Closeout and Start-up 10
Information:
• The section number and title are the file names (i.e. 2000500 General
Provisions.doc) and are also included in the beginning of each document as
well as a title (with a set style).
• All files are located in the same folder.
Here is the current macro I am working with that was provided by someone on
this site: This macro does not input the correct page count for each file,
in fact it places the 1st file’s page count for each file instead.
Looks like this:
200500 GENERAL PROVISIONS test.doc 3
SECTION 200523 VALVES DRAFT with index codes.doc 3
Table style settings-example.doc 3
The macro will put the correct page count ONLY if all the files are open.
But considering I am trying to use this macro for 50+ documents at a time,
this is not a viable solution. Any help would be GREATLY appreciated; I’ve
been working on this for months. Thanks.
Sub TOCpgcnt()
'
' TOCpgcnt Macro
'
'
Dim fd As FileDialog
Dim PathToUse As String
Dim SourceFile As String
Dim Target As Document
Dim Source As Document
Dim numpages As Long
Set Target = ActiveDocument
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select the folder containing the files."
If .Show = -1 Then
PathToUse = .SelectedItems(1) & "\"
Else
End If
End With
Set fd = Nothing
SourceFile = Dir$(PathToUse & "*.doc")
Do While SourceFile <> ""
Set Source = Documents.Open(PathToUse & SourceFile)
numpages = Source.BuiltInDocumentProperties(wdPropertyPages)
Target.Range.InsertAfter Source.Name & vbTab & numpages & vbCrLf
Source.Close wdDoNotSaveChanges
SourceFile = Dir$
Loop
End Sub
I want to create a TOC with the Title and Individual Section Page Counts
using separate Individual Files to look like this:
Section No. Title No. of Pages
200500 General Provisions 5
200505 Project Closeout and Start-up 10
Information:
• The section number and title are the file names (i.e. 2000500 General
Provisions.doc) and are also included in the beginning of each document as
well as a title (with a set style).
• All files are located in the same folder.
Here is the current macro I am working with that was provided by someone on
this site: This macro does not input the correct page count for each file,
in fact it places the 1st file’s page count for each file instead.
Looks like this:
200500 GENERAL PROVISIONS test.doc 3
SECTION 200523 VALVES DRAFT with index codes.doc 3
Table style settings-example.doc 3
The macro will put the correct page count ONLY if all the files are open.
But considering I am trying to use this macro for 50+ documents at a time,
this is not a viable solution. Any help would be GREATLY appreciated; I’ve
been working on this for months. Thanks.
Sub TOCpgcnt()
'
' TOCpgcnt Macro
'
'
Dim fd As FileDialog
Dim PathToUse As String
Dim SourceFile As String
Dim Target As Document
Dim Source As Document
Dim numpages As Long
Set Target = ActiveDocument
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select the folder containing the files."
If .Show = -1 Then
PathToUse = .SelectedItems(1) & "\"
Else
End If
End With
Set fd = Nothing
SourceFile = Dir$(PathToUse & "*.doc")
Do While SourceFile <> ""
Set Source = Documents.Open(PathToUse & SourceFile)
numpages = Source.BuiltInDocumentProperties(wdPropertyPages)
Target.Range.InsertAfter Source.Name & vbTab & numpages & vbCrLf
Source.Close wdDoNotSaveChanges
SourceFile = Dir$
Loop
End Sub