Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to transfer sections of a Word Template to a new doc, please

Status
Not open for further replies.

treschouette

Programmer
Oct 22, 2002
2
US
I am at the initial stages of developing a VB application that will select certain sections of an existing Word template -- for instance, one section per checkbox control -- and transfer those sections to a new word document.

Since this involves transfering Word to Word, so to speak, I am unsure of the best way to go about it and am, admittedly, relatively new to VB.

Any help would be vastly appreciated,

Thank you.
 
Here's how I copy bookmarks from a template and then paste them to the end of my catalog document so I can continue to merge more records. Hope this helps!

strTemplPath="C:\yourpath\"

'Start Word and get template info
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then 'word not open
Set objWord = CreateObject("Word.Application")
objWord.Application.Visible = True
Err.Clear

objWord.Documents.Add Template:=strTemplPath & "Merge1.dot"
'copy all the bookmarks in my template to the clipboard
ActiveDocument.Range.Copy
ActiveDocument.Close
'open my catalog doucment
objWord.Documents.Open (strTemplPath & "catalog.doc")
AppActivate "Microsoft Word", 1
'go to the end of my document
Set myrange = ActiveDocument.Range(Start:=ActiveDocument.Content.End - 1, End:=ActiveDocument.Content.End - 1)

'paste new bookmarks
myrange.Paste

ElseIf Err.Number <> 0 Then
MsgBox Err.Number & Err.Description & &quot;An unexpected error has occurred.&quot;
Exit Function
Else

'catalog document already open
Set myrange = ActiveDocument.Range(Start:=ActiveDocument.Content.End - 1, End:=ActiveDocument.Content.End - 1)
myrange.Paste
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top