G
Greg Maxey
I am playing with a macro that I first saw posted by Doug Robbins. It take
each page of a document and saves as a new document. I am trying to provide
a User interface with where the files are to be saved, but I can't work out
combine two strings. One is the Path and the other is the File name.
I am able to get both strings individually, but when I try to combine them,
the Full Path and Name looks something like this which is an invalid file
name: ""C\My Documents\""FileNam""
Here is the code. How do you combine tow strings like "Path\" and
"FileName" to come of with "Path\Filename" ?
Thanks.
Sub SaveEachPageOfCurrentDocumentAsANewDocument()
Dim pCounter As Long
Dim pNumPages As Long
Dim pParent As Document
Dim pChild As Document
Dim pParentName As String
Dim pChildName As String
Dim pChildNameRange As Range
Dim PathToUse As String
If ActiveDocument.Saved = False Then
Documents.Save NoPrompt:=False, _
OriginalFormat:=wdOriginalDocumentFormat
End If
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
Set pParent = ActiveDocument
pParentName = pParent.FullName
Selection.HomeKey Unit:=wdStory
pNumPages = pParent.BuiltInDocumentProperties(wdPropertyPages)
pCounter = 0
While pCounter < pNumPages
pCounter = pCounter + 1
pParent.Bookmarks("\Page").Range.Cut
Set pChild = Documents.Add
pChild.Range.Paste
Set pChildNameRange = pChild.Range
pChildNameRange.Collapse wdCollapseStart '
pChildNameRange.Expand Unit:=wdParagraph
pChildNameRange.MoveEnd Unit:=wdCharacter, Count:=-1
pChildName = pChildNameRange
pChild.SaveAs FileName:="PathToUse & pChildName"
pChild.Close
Wend
pParent.Close SaveChanges:=wdDoNotSaveChanges
Documents.Open pParentName
End Sub
each page of a document and saves as a new document. I am trying to provide
a User interface with where the files are to be saved, but I can't work out
combine two strings. One is the Path and the other is the File name.
I am able to get both strings individually, but when I try to combine them,
the Full Path and Name looks something like this which is an invalid file
name: ""C\My Documents\""FileNam""
Here is the code. How do you combine tow strings like "Path\" and
"FileName" to come of with "Path\Filename" ?
Thanks.
Sub SaveEachPageOfCurrentDocumentAsANewDocument()
Dim pCounter As Long
Dim pNumPages As Long
Dim pParent As Document
Dim pChild As Document
Dim pParentName As String
Dim pChildName As String
Dim pChildNameRange As Range
Dim PathToUse As String
If ActiveDocument.Saved = False Then
Documents.Save NoPrompt:=False, _
OriginalFormat:=wdOriginalDocumentFormat
End If
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
Set pParent = ActiveDocument
pParentName = pParent.FullName
Selection.HomeKey Unit:=wdStory
pNumPages = pParent.BuiltInDocumentProperties(wdPropertyPages)
pCounter = 0
While pCounter < pNumPages
pCounter = pCounter + 1
pParent.Bookmarks("\Page").Range.Cut
Set pChild = Documents.Add
pChild.Range.Paste
Set pChildNameRange = pChild.Range
pChildNameRange.Collapse wdCollapseStart '
pChildNameRange.Expand Unit:=wdParagraph
pChildNameRange.MoveEnd Unit:=wdCharacter, Count:=-1
pChildName = pChildNameRange
pChild.SaveAs FileName:="PathToUse & pChildName"
pChild.Close
Wend
pParent.Close SaveChanges:=wdDoNotSaveChanges
Documents.Open pParentName
End Sub