T
Tony Bonacci
I have a Word 2000 Template that has a bunch of bookmarks and a Data Entry
Form, that the user creates a New Document off of. When the user creates a
new document based on this template, there is a Macro that the user can run
that loads a user entry Form allowing the user has to enter data. When the
user clicks the OK button on the form the following 2 things happen:
1. All the bookmarks within the document get updated based on data from
the User Entry Form
2. At the end of the document, a particular Word document (Test.doc) is
inserted at the "Attachment" bookmark
Everything works fine the first time the user clicks the OK button. However,
if the user reruns the same macro within the same document, re-enters
different data on the user entry form and clicks the OK button, all the
bookmarks update properly, but the inserted file gets added after the 1st
one (the 1st one does not get cleared out) - so the user has 2 inserted
files. For instance, the first time the user runs the letter there is 3
pages (2 pages + 1 File), and if the user runs it again, there will be 4
pages (2 pages + 2 Files - 1st one and now the 2nd one), and so on...
Basically, each time the user clicks the OK button, the appropriate file
keeps getting appended to the end.
My problem is, how can I remove the file (Test.doc) that was inserted on the
1st run before we insert the file on the 2nd run? Is there a way to delete
the entire page before we insert the file, that way all the data is cleared
leaving me with only 2 pages, before I do my insert? My sample code of
inserting the file is below:
Dim bmRange As Range
' This is my bookmark where I want to add the file
Set bmRange = ActiveDocument.Bookmarks("Attachment").Range
With bmRange
.Collapse Direction:=wdCollapseEnd
' Insert a Page Break after the bookmark so that the file being
inserted is on it's own page
.InsertBreak Type:=wdPageBreak
' Insert the Test Document
.InsertFile FileName:="C:\Test.doc", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
.Collapse Direction:=wdCollapseEnd
End With
Form, that the user creates a New Document off of. When the user creates a
new document based on this template, there is a Macro that the user can run
that loads a user entry Form allowing the user has to enter data. When the
user clicks the OK button on the form the following 2 things happen:
1. All the bookmarks within the document get updated based on data from
the User Entry Form
2. At the end of the document, a particular Word document (Test.doc) is
inserted at the "Attachment" bookmark
Everything works fine the first time the user clicks the OK button. However,
if the user reruns the same macro within the same document, re-enters
different data on the user entry form and clicks the OK button, all the
bookmarks update properly, but the inserted file gets added after the 1st
one (the 1st one does not get cleared out) - so the user has 2 inserted
files. For instance, the first time the user runs the letter there is 3
pages (2 pages + 1 File), and if the user runs it again, there will be 4
pages (2 pages + 2 Files - 1st one and now the 2nd one), and so on...
Basically, each time the user clicks the OK button, the appropriate file
keeps getting appended to the end.
My problem is, how can I remove the file (Test.doc) that was inserted on the
1st run before we insert the file on the 2nd run? Is there a way to delete
the entire page before we insert the file, that way all the data is cleared
leaving me with only 2 pages, before I do my insert? My sample code of
inserting the file is below:
Dim bmRange As Range
' This is my bookmark where I want to add the file
Set bmRange = ActiveDocument.Bookmarks("Attachment").Range
With bmRange
.Collapse Direction:=wdCollapseEnd
' Insert a Page Break after the bookmark so that the file being
inserted is on it's own page
.InsertBreak Type:=wdPageBreak
' Insert the Test Document
.InsertFile FileName:="C:\Test.doc", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
.Collapse Direction:=wdCollapseEnd
End With