Merge Word Document and a Template

  • Thread starter blanic via AccessMonster.com
  • Start date
B

blanic via AccessMonster.com

Here is my code, it opens both as new files instead of opening the template
and adding the document
I have also reversed the add and open lines to see if it made a difference,
same results.


Dim wdApp As Word.Application
Dim doc As Word.Document
Dim strTemplate As String
Dim RetVal
Dim TheDate As String ' Declare variables.
Dim Today As String
Dim Year As String
Dim Yar As String
Dim month As String
Dim Mont As String
Dim fs As New FileSystemObject
Dim SourceFile, DestinationFile



TheDate = Now
Today = DatePart("d", TheDate)
Year = DatePart("yyyy", TheDate)
Yar = Right(Year, 2)
month = DatePart("m", TheDate)
Mont = rtnMonth(month)


Set wdApp = New Word.Application
wdApp.Visible = True
strTemplate = "E:\CGInst\Rpts\COSIG.dot"
Set doc = wdApp.Documents.Open(strTemplate)
Set doc = wdApp.Documents.Add("E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300."
+ Today)
With wdApp.ActiveDocument.PageSetup

.TopMargin = InchesToPoints(0.35)
.BottomMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.25)
End With
Set ftRng = wdApp.ActiveDocument.Content
With ftRng.Font
.Bold = True

End With
 
G

Guest

Try adding the document with the Template option instead using open, then
saving it as your document.

Set doc = wdApp.Documents.Add(strTemplate)
'do some stuff
doc.saveas "E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300. + Today.doc"
 
B

blanic via AccessMonster.com

Nope, didnt work, but I did find something interesting, but it doesnt work.
AttachedTemplate is suppose to attach the template, but it says there is no
active document. The way you also suggested just saved the .dot as 2300.
today, which is not what I want. I want to essentially merge the 2 togehter.
The COSIG.dot has a footer I want, and then the data comes from the 2300. I
would like to merge them as 1 document, and I have the template already
though, and I just wnat the 2300 to open on the cosig.dot template. Thanks
again

Set wdApp = New Word.Application
wdApp.Visible = True
strTemplate = "E:\CGInst\Rpts\COSIG.dot"
Set doc = wdApp.Documents.Open("E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300.
" + Today)


With wdApp.ActiveDocument.PageSetup

.TopMargin = InchesToPoints(0.35)
.BottomMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.25)
End With
ActiveDocument.AttachedTemplate = strTemplate

Set ftRng = wdApp.ActiveDocument.Content
With ftRng.Font
.Bold = True

End With


Try adding the document with the Template option instead using open, then
saving it as your document.

Set doc = wdApp.Documents.Add(strTemplate)
'do some stuff
doc.saveas "E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300. + Today.doc"
Here is my code, it opens both as new files instead of opening the template
and adding the document
[quoted text clipped - 39 lines]
 
B

blanic via AccessMonster.com

I am also working on documents.open, there is a template area, but I cant
seem to get it to work.
I have tried merge and all I can find here to read, nothing yet works for
what im lookin for.
Nope, didnt work, but I did find something interesting, but it doesnt work.
AttachedTemplate is suppose to attach the template, but it says there is no
active document. The way you also suggested just saved the .dot as 2300.
today, which is not what I want. I want to essentially merge the 2 togehter.
The COSIG.dot has a footer I want, and then the data comes from the 2300. I
would like to merge them as 1 document, and I have the template already
though, and I just wnat the 2300 to open on the cosig.dot template. Thanks
again

Set wdApp = New Word.Application
wdApp.Visible = True
strTemplate = "E:\CGInst\Rpts\COSIG.dot"
Set doc = wdApp.Documents.Open("E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300.
" + Today)


With wdApp.ActiveDocument.PageSetup

.TopMargin = InchesToPoints(0.35)
.BottomMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.25)
End With
ActiveDocument.AttachedTemplate = strTemplate

Set ftRng = wdApp.ActiveDocument.Content
With ftRng.Font
.Bold = True

End With
Try adding the document with the Template option instead using open, then
saving it as your document.
[quoted text clipped - 8 lines]
 
G

Guest

That should have been what my earlier post did, open the template.

Set doc = wdApp.Documents.Add(strTemplate)
Part of the problem might be you are using the same doc variable for both
files. However I am still not sure how to merge them, but I'm looking. Thanks.


blanic via AccessMonster.com said:
I am also working on documents.open, there is a template area, but I cant
seem to get it to work.
I have tried merge and all I can find here to read, nothing yet works for
what im lookin for.
Nope, didnt work, but I did find something interesting, but it doesnt work.
AttachedTemplate is suppose to attach the template, but it says there is no
active document. The way you also suggested just saved the .dot as 2300.
today, which is not what I want. I want to essentially merge the 2 togehter.
The COSIG.dot has a footer I want, and then the data comes from the 2300. I
would like to merge them as 1 document, and I have the template already
though, and I just wnat the 2300 to open on the cosig.dot template. Thanks
again

Set wdApp = New Word.Application
wdApp.Visible = True
strTemplate = "E:\CGInst\Rpts\COSIG.dot"
Set doc = wdApp.Documents.Open("E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300.
" + Today)


With wdApp.ActiveDocument.PageSetup

.TopMargin = InchesToPoints(0.35)
.BottomMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.25)
End With
ActiveDocument.AttachedTemplate = strTemplate

Set ftRng = wdApp.ActiveDocument.Content
With ftRng.Font
.Bold = True

End With
Try adding the document with the Template option instead using open, then
saving it as your document.
[quoted text clipped - 8 lines]
 
G

Guest

This is the best I could do. It merged the template with my document but it
looked ugly.

Dim doc As Document
Dim strTemplate As String
strTemplate = "E:\CGInst\Rpts\COSIG.dot"
Set doc = Documents.Add(strTemplate)
doc.Merge FileName:="E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300." + Today


Ralph said:
That should have been what my earlier post did, open the template.

Set doc = wdApp.Documents.Add(strTemplate)
Part of the problem might be you are using the same doc variable for both
files. However I am still not sure how to merge them, but I'm looking. Thanks.


blanic via AccessMonster.com said:
I am also working on documents.open, there is a template area, but I cant
seem to get it to work.
I have tried merge and all I can find here to read, nothing yet works for
what im lookin for.
Nope, didnt work, but I did find something interesting, but it doesnt work.
AttachedTemplate is suppose to attach the template, but it says there is no
active document. The way you also suggested just saved the .dot as 2300.
today, which is not what I want. I want to essentially merge the 2 togehter.
The COSIG.dot has a footer I want, and then the data comes from the 2300. I
would like to merge them as 1 document, and I have the template already
though, and I just wnat the 2300 to open on the cosig.dot template. Thanks
again

Set wdApp = New Word.Application
wdApp.Visible = True
strTemplate = "E:\CGInst\Rpts\COSIG.dot"
Set doc = wdApp.Documents.Open("E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300.
" + Today)


With wdApp.ActiveDocument.PageSetup

.TopMargin = InchesToPoints(0.35)
.BottomMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.25)
End With
ActiveDocument.AttachedTemplate = strTemplate

Set ftRng = wdApp.ActiveDocument.Content
With ftRng.Font
.Bold = True

End With

Try adding the document with the Template option instead using open, then
saving it as your document.
[quoted text clipped - 8 lines]

End With
 
B

blanic via AccessMonster.com

Ya it works, but boy is it ugly. There has to be a better way to merge it.
Or use the template and open the document on it? Just dont know how.
This is the best I could do. It merged the template with my document but it
looked ugly.

Dim doc As Document
Dim strTemplate As String
strTemplate = "E:\CGInst\Rpts\COSIG.dot"
Set doc = Documents.Add(strTemplate)
doc.Merge FileName:="E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300." + Today
That should have been what my earlier post did, open the template.
[quoted text clipped - 43 lines]
 
G

Guest

You might try posting your question in the Word Programming discussion group,
there's bound to be someone who can answer your question. Good luck.

blanic via AccessMonster.com said:
Ya it works, but boy is it ugly. There has to be a better way to merge it.
Or use the template and open the document on it? Just dont know how.
This is the best I could do. It merged the template with my document but it
looked ugly.

Dim doc As Document
Dim strTemplate As String
strTemplate = "E:\CGInst\Rpts\COSIG.dot"
Set doc = Documents.Add(strTemplate)
doc.Merge FileName:="E:\CGinst\RPTS\" + Yar + "\" + Mont + "\2300." + Today
That should have been what my earlier post did, open the template.
[quoted text clipped - 43 lines]
 

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