I have been using the following macro to unmerge a long document and
create 6 labeled documents in same folder, but it does not warn about
overwriting an existing file. I would appreciate advise on how to add
that function.Thanks in advance!
Sub UnMerge()
Dim docNew As Word.Document
Dim sctsActive As Word.Sections
Dim astrFiles(1 To 6) As String
Dim i As Long
astrFiles(1) = "Label.doc"
astrFiles(2) = "Address.doc"
astrFiles(3) = "Data Entry.doc"
astrFiles(4) = "Rep.doc"
astrFiles(5) = "AppFile.doc"
astrFiles(6) = "Application.doc"
Set sctsActive = Word.ActiveDocument.Sections
For i = 1 To 6
Set docNew = Documents.Add
With docNew
sctsActive(i).Range.Copy
.Range.Paste
.SaveAs astrFiles(i)
End With
Next i
End Sub
Doug Robbins - Word MVP - 31 Mar 2006 05:02 GMT
You will probably find something to help you in the article "How to save a
document using a filename that gets incremented by 1 each time if the
filename already exists":
http://www.word.mvps.org/FAQs/MacrosVBA/SaveIncrementedFilename.htm

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I have been using the following macro to unmerge a long document and
> create 6 labeled documents in same folder, but it does not warn about
[quoted text clipped - 25 lines]
>
> End Sub
mharris357@earthlink.net - 31 Mar 2006 05:53 GMT
Actually, that did not work for me. I want a warning, "Overwrite file?"
that will allow me to relabel that file. It needs to fit into the
existing unmerge macro.
Doug Robbins - Word MVP - 31 Mar 2006 15:49 GMT
You need to make use of the information to which I directed you. This may
not be exactly what you want as it will just stop the routine. You may
instead want to display an input box into which the user can insert a new
filename:
Dim docNew As Word.Document
Dim sctsActive As Word.Sections
Dim astrFiles(1 To 6) As String
Dim i As Long
astrFiles(1) = "Label.doc"
astrFiles(2) = "Address.doc"
astrFiles(3) = "Data Entry.doc"
astrFiles(4) = "Rep.doc"
astrFiles(5) = "AppFile.doc"
astrFiles(6) = "Application.doc"
Set sctsActive = Word.ActiveDocument.Sections
For i = 1 To 6
Set docNew = Documents.Add
With docNew
sctsActive(i).Range.Copy
.Range.Paste
If Dir(astrFiles(i)) = "" Then
.SaveAs astrFiles(i)
Else
MsgBox "The document " & astrFiles(i) & "already exists"
Exit Sub
End If
End With
Next i

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Actually, that did not work for me. I want a warning, "Overwrite file?"
> that will allow me to relabel that file. It needs to fit into the
> existing unmerge macro.
Jezebel - 31 Mar 2006 09:38 GMT
The SaveAs function doesn't check if the file exists ... it just overwrites.
You need to check for yourself, eg using Dir().
>I have been using the following macro to unmerge a long document and
> create 6 labeled documents in same folder, but it does not warn about
[quoted text clipped - 25 lines]
>
> End Sub