Hi,
I am a real newbie to script languages. I am trying to write a program that
takes a mail merge document and scripts it out into many sub-documents. With
the help of google I was able to find a script with a little tweaking is
doing what I need it to. I have hit a bump though with using the Save As
feature. I want the final document to be default save as value when saving in
Word (the first line). Here is the code I have written based on searching and
pasting together. I get a compliation error that states there is a missing
argument. I just can't figure out where. Any help is appreciated.
Thanks.
Sub SaveAllSubDocs(ByRef doc As Word.Document)
Dim subdoc As Word.Subdocument
Dim newdoc As Word.Document
Dim docCounter As Long
docCounter = 1
'Must be in MasterView to work with
'Subdocs as separate files
doc.ActiveWindow.View = wdMasterView
For Each subdoc In doc.Subdocuments
Set newdoc = subdoc.Open
'Remove NextPage section breaks
'originating from mailmerge
RemoveAllSectionBreaks newdoc
'Save as
With newdoc
Sub.FileSaveAs()
With Dialogs(wdDialogFileSaveAs)
.Name = ActiveDocument.BuiltInDocumentProperties("Title")
.Show
End With
End Sub
With Dialogs(wdDialogFileSaveAs)
.Name = ActiveDocument.BuiltInDocumentProperties("Title")
.Show
Next subdoc
HKK - 14 Mar 2005 19:36 GMT
Here is all the code I am using...Still now working for Save As :(
Sub SaveRecsAsFiles()
' Convert all sections to Subdocs
AllSectionsToSubDoc ActiveDocument
'Save each Subdoc as a separate file
SaveAllSubDocs ActiveDocument
End Sub
Sub AllSectionsToSubDoc(ByRef doc As Word.Document)
Dim secCounter As Long
Dim NrSecs As Long
NrSecs = doc.Sections.Count
'Start from the end because creating
'Subdocs inserts additional sections
For secCounter = NrSecs - 1 To 1 Step -1
doc.Subdocuments.AddFromRange _
doc.Sections(secCounter).Range
Next secCounter
End Sub
Sub SaveAllSubDocs(ByRef doc As Word.Document)
Dim subdoc As Word.Subdocument
Dim newdoc As Word.Document
Dim docCounter As Long
docCounter = 1
'Must be in MasterView to work with
'Subdocs as separate files
doc.ActiveWindow.View = wdMasterView
For Each subdoc In doc.Subdocuments
Set newdoc = subdoc.Open
'Remove NextPage section breaks
'originating from mailmerge
RemoveAllSectionBreaks newdoc
With newdoc
With Dialogs(wdDialogFileSaveAs)
.Name = ActiveDocument.BuiltInDocumentProperties("Title")
.Show
.Close
End With
docCounter = docCounter + 1
Next subdoc
End Sub
Sub RemoveAllSectionBreaks(doc As Word.Document)
With doc.Range.Find
.ClearFormatting
.Text = "^b"
With .Replacement
.ClearFormatting
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
End Sub
Word Heretic - 18 Mar 2005 13:44 GMT
G'day HKK <HKK@discussions.microsoft.com>,
#1: Is commenting your code impossible?
#2: No idea what you are after mate, help me out please :-)
Steve Hudson - Word Heretic
steve from wordheretic.com (Email replies require payment)
Without prejudice
HKK reckoned:
>Here is all the code I am using...Still now working for Save As :(
>
[quoted text clipped - 50 lines]
>End With
>End Sub
Word Heretic - 18 Mar 2005 13:44 GMT
G'day HKK <HKK@discussions.microsoft.com>,
Which line fails?
Steve Hudson - Word Heretic
steve from wordheretic.com (Email replies require payment)
Without prejudice
HKK reckoned:
>Hi,
>I am a real newbie to script languages. I am trying to write a program that
[quoted text clipped - 33 lines]
> .Show
>Next subdoc