PC Review


Reply
Thread Tools Rate Thread

Create new Word document from template

 
 
Nigel Blakey
Guest
Posts: n/a
 
      20th Feb 2009
I have an Access 2003 database that lists several hundred standard letters
saved as Word 2003 Templates. Selecting one of the documents in a List Box
will trigger an Event Procedure using the Hyperlink.Follow method. This
starts Word and opens the Word document successfully. But the document is a
Word template (.dot) and I want to create a (.doc) copy of the template
direct from Access.

Does anyone have any ideas?

Thank you
Nigel Blakey
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      22nd Feb 2009
Hi Nigel,

This bit of code is out of one of my projects that I got help from this
forum with. It creates a word doc from a template and then copies data to
fields. I have left in the code to copy data to fields because you might also
find that helpful.

Note: The word document is not saved with this code so will need
modification of this line
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
if you want to save it.

Private Sub PrintWordDoc()

Dim objWord As Object
Dim strPathFileName As String
Dim i As Long


'Save the Forms textbox values to variables
'using space in lieu of null values.
'(Error produced on Word doc if zero length string
'is used in lieu of null value; hence use of space if Null)

strReceiptNo = Nz(Me.ReceiptNo, " ")
strOrganizationName = Nz(Me.EROrganizationPost, " ")
strAddr1 = Nz(Me.ErAddrPost1, " ")
strAddr2 = Nz(Me.ERAddrPost2, " ")
strLocal = Nz(Me.ERLocalityPost, " ")
strState = Nz(Me.ERStatePost, " ")
strPostCode = Nz(Me.ERPostCodePost, " ")

Set objWord = CreateObject("Word.Application")

'Save required path and filename of template file
strPathFileName = CurDir & "\" & "ERLA Template.dot"


With objWord
'Create a new Word document based on the template
.documents.Add template:=strPathFileName
.Visible = False 'Can be True
.ActiveDocument.Variables("RecptNo").Value = strReceiptNo
.ActiveDocument.Variables("EligRecipient").Value = strOrganizationName
.ActiveDocument.Variables("PostalAddress").Value = _
Trim(strAddr1 & " " & strAddr2 & " " & strLocal & " " _
& strState & " " & strPostCode)

.ActiveDocument.Fields.Update

If .ActiveWindow.View.ShowFieldCodes = True Then
.ActiveWindow.View.ShowFieldCodes = False
End If


.ActiveDocument.PrintOut

.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
.Quit
End With
set objWord = Nothing
Exit Sub






--
Regards,

OssieMac


"Nigel Blakey" wrote:

> I have an Access 2003 database that lists several hundred standard letters
> saved as Word 2003 Templates. Selecting one of the documents in a List Box
> will trigger an Event Procedure using the Hyperlink.Follow method. This
> starts Word and opens the Word document successfully. But the document is a
> Word template (.dot) and I want to create a (.doc) copy of the template
> direct from Access.
>
> Does anyone have any ideas?
>
> Thank you
> Nigel Blakey

 
Reply With Quote
 
Nigel Blakey
Guest
Posts: n/a
 
      2nd Mar 2009
Hi Ossiemac,

That's so helpfull! Thanks very much.

Cheers,
Nigel
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word document loses attached template when saved in Sharepoint document library Vadim Rapp Microsoft Word Document Management 0 2nd Dec 2008 07:42 PM
Create Word Document with Specified Word Template from Access Report Michael Microsoft Access Reports 0 11th Jun 2007 01:58 PM
Autotext exclusive to a New Document Template I Create in Word 200 =?Utf-8?B?S00x?= Microsoft Word Document Management 2 23rd Jan 2005 04:03 AM
How do I create a document template in Word? =?Utf-8?B?TmV3R3V5?= Microsoft Word Document Management 3 6th Dec 2004 03:48 PM
Create New Document from Template Ross Payne Microsoft Word New Users 2 2nd Aug 2004 05:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:11 AM.