How to automatically create missing subdocuments ?

E

E B

Hi,

I Have a word document that is automatically generated by an application.
This document refers to subdocuments but some of them are (sometime)
missing.
I'd like to write a vba macro which will check all subdocuments and will
create the missing ones.
The following code does not work:


Sub createMissingSubDocuments()

For Each sd In ActiveDocument.Subdocuments
file_path = sd.Path & Application.PathSeparator & sd.Name
If sd.HasFile = True Then
'MsgBox subdoc.Path & Application.PathSeparator & subdoc.Name
Else
Documents.Add.SaveAs FileName:=file_path,
fileformat:=wdFormatRTF
End If

Next
End Sub

When reaching Documents.Add.saveAs ... an error is raised saying that
the file already exists (but actually it does not exist)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top