R
Rashid Khan
Hello Group,
I have seen and copied the following macro from the NG. It is suppose to
save each page as a seperate file using the first line of the page as file
name.
This macro works fine but it does not save the first line of my document as
a file name. My document has the first line as
1) SI-797-066-MOL-001_001
2) SI-797-066-MOL-001_002
3) SI-797-066-MOL-002_001
4) SI-797-066-MOL-002_002
............ so on so forth
The result I get after running the macro is
1) SI
2) SI1
3) SI2
4) SI3
....... so on
What am I missing?
The macro seems to take the first two characters only (eg. SI in this case)
and increment it.
What I need is the complete first line to be cut and saved with that name as
a word document file.
Any help and suggestions would be greatly appreciated.
R Khan
Dim i As Integer
Dim iNumPages As Integer
Dim sCurrentDoc As String
sCurrentDoc = ActiveDocument.Name
'Get the current document's name
iNumPages = ActiveDocument.ComputeStatistics(wdStatisticPages)
'Get the number of pages
For i = 1 To iNumPages
'For as many times as there are pages
Selection.GoTo What:=wdGoToPage, which:=wdGoToAbsolute, Count:=i
'Goto pagenumber i
Selection.GoTo What:=wdGoToBookmark, Name:="\Page"
'Select this page
Selection.Copy
'Copy the selection
Documents.Add
'Add a new document
Selection.Paste
'Paste
ActiveDocument.SaveAs , FileFormat:=wdFormatText
'Save the new document using first line as file name
Selection.HomeKey Unit:=wdStory
' Go to Top of Page
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
' Highlight first line
Selection.Cut
' Delete first line
ActiveDocument.SaveAs , FileFormat:=wdFormatText
' Save File Again
ActiveDocument.Close
'Close this new document
Documents(sCurrentDoc).Activate
'Activate the document where we started from
Next i
End Sub
I have seen and copied the following macro from the NG. It is suppose to
save each page as a seperate file using the first line of the page as file
name.
This macro works fine but it does not save the first line of my document as
a file name. My document has the first line as
1) SI-797-066-MOL-001_001
2) SI-797-066-MOL-001_002
3) SI-797-066-MOL-002_001
4) SI-797-066-MOL-002_002
............ so on so forth
The result I get after running the macro is
1) SI
2) SI1
3) SI2
4) SI3
....... so on
What am I missing?
The macro seems to take the first two characters only (eg. SI in this case)
and increment it.
What I need is the complete first line to be cut and saved with that name as
a word document file.
Any help and suggestions would be greatly appreciated.
R Khan
Dim i As Integer
Dim iNumPages As Integer
Dim sCurrentDoc As String
sCurrentDoc = ActiveDocument.Name
'Get the current document's name
iNumPages = ActiveDocument.ComputeStatistics(wdStatisticPages)
'Get the number of pages
For i = 1 To iNumPages
'For as many times as there are pages
Selection.GoTo What:=wdGoToPage, which:=wdGoToAbsolute, Count:=i
'Goto pagenumber i
Selection.GoTo What:=wdGoToBookmark, Name:="\Page"
'Select this page
Selection.Copy
'Copy the selection
Documents.Add
'Add a new document
Selection.Paste
'Paste
ActiveDocument.SaveAs , FileFormat:=wdFormatText
'Save the new document using first line as file name
Selection.HomeKey Unit:=wdStory
' Go to Top of Page
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
' Highlight first line
Selection.Cut
' Delete first line
ActiveDocument.SaveAs , FileFormat:=wdFormatText
' Save File Again
ActiveDocument.Close
'Close this new document
Documents(sCurrentDoc).Activate
'Activate the document where we started from
Next i
End Sub