BoatwrenchV8
12-08-2008, 08:00 PM
Hello,
I have a large collection of word files that have number format file names. Sorting thru them all to find out what they specifically referr to is going to be a nightmare. The file name does not contain any human understandable information. In each word file, the header contains a table with descriptive information and so does the footer. In the body of the document is another table with information. I do not need to extract any information from the body table. I am only interested in the header and footer tables. The number of rows in the tables in the header and footer are not always the same across different documents but are the same through out a single document.
Basically, I want to create an index of the descriptive information extracted from the files.
What I want to do:
1. Select a start directory
2. Have the macro open the first word document
3. Select the header and determine the number of rows in it
4. Copy the information (string text) one row at a time into variables (array)
5. Go to the footer and determine the number of rows there.
6. Copy the information (string text) one row at a time into variables
7. Close the word document.
8. Paste the copied data into the index document
9. Repeat steps 2 thru 8 for the rest of the documents in the directory.
What I have come up with so far:
*************************************
Sub Macro15()
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.Information(wdWithInTable) Then
Selection.Tables(1).Select
MsgBox "this is the table. It has " & Selection.Information(wdMaximumNumberOfRows) _
& " rows", , "Total rows"
End If
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.MoveDown Unit:=wdLine, Count:=1
If Selection.Information(wdWithInTable) Then
Selection.Tables(1).Select
MsgBox "this is the table. It has " & Selection.Information(wdMaximumNumberOfRows) _
& " rows", , "Total rows"
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
**************************************
The above code only determines the number of row each table has. I plan on using the number of rows to control the number of times I tab thru the tables copying the data in each row.
One problem is the footer table has a single blank line between the top of the footer and the top of the table. I do not know if all the files have just 1 blank line or not.
Isn't there an easier way to get to a table in the header and a table in the footer, extract the info, paste somewhere else, open the next one and keep going?
I feel like I am taking the great circle route and I am over complicating it. I have the algorhythm figured out. I usually use the macro recorder and then tune things up a little but this program is turning out to be a real challenge.
Please advise,
Thank you.
I have a large collection of word files that have number format file names. Sorting thru them all to find out what they specifically referr to is going to be a nightmare. The file name does not contain any human understandable information. In each word file, the header contains a table with descriptive information and so does the footer. In the body of the document is another table with information. I do not need to extract any information from the body table. I am only interested in the header and footer tables. The number of rows in the tables in the header and footer are not always the same across different documents but are the same through out a single document.
Basically, I want to create an index of the descriptive information extracted from the files.
What I want to do:
1. Select a start directory
2. Have the macro open the first word document
3. Select the header and determine the number of rows in it
4. Copy the information (string text) one row at a time into variables (array)
5. Go to the footer and determine the number of rows there.
6. Copy the information (string text) one row at a time into variables
7. Close the word document.
8. Paste the copied data into the index document
9. Repeat steps 2 thru 8 for the rest of the documents in the directory.
What I have come up with so far:
*************************************
Sub Macro15()
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.Information(wdWithInTable) Then
Selection.Tables(1).Select
MsgBox "this is the table. It has " & Selection.Information(wdMaximumNumberOfRows) _
& " rows", , "Total rows"
End If
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.MoveDown Unit:=wdLine, Count:=1
If Selection.Information(wdWithInTable) Then
Selection.Tables(1).Select
MsgBox "this is the table. It has " & Selection.Information(wdMaximumNumberOfRows) _
& " rows", , "Total rows"
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
**************************************
The above code only determines the number of row each table has. I plan on using the number of rows to control the number of times I tab thru the tables copying the data in each row.
One problem is the footer table has a single blank line between the top of the footer and the top of the table. I do not know if all the files have just 1 blank line or not.
Isn't there an easier way to get to a table in the header and a table in the footer, extract the info, paste somewhere else, open the next one and keep going?
I feel like I am taking the great circle route and I am over complicating it. I have the algorhythm figured out. I usually use the macro recorder and then tune things up a little but this program is turning out to be a real challenge.
Please advise,
Thank you.