Create new WORD & add Autotext

calvinle

Registered User.
Local time
Today, 02:01
Joined
Sep 26, 2014
Messages
332
Hi,

I just wonder if anyone can provided any information on creating a new word and insert autotext from a template (usually: Normal.dot)
I have looked many sites online, and it mainly explain the code to use within the word document macro, but not from Access VBA.

A help will be appreciated.

Thanks
 
if your looking to merge data from your db into a word document, take a look at Albert Kallal's Super easy word merge
http://www.kallal.ca/msaccess/msaccess.html

Thanks for the link, but I want the WORD document to open up itself base on my template, and add the autotext without the user having to go in WORD and starts adding themself.

Thanks for the link anyways. ;)
 
Here is what I come so far, but it doesnt work:

Code:
Dim objWord As Word.Application
Dim doc As Word.Document
 Set objWord = CreateObject("Word.Application")
 objWord.Visible = True
Set doc = objWord.Documents.Open("C:\Users\yygh98\Desktop\TEMPLATE.dot")
 With objWord.selection
  ActiveDocument.AttachedTemplate _
  .BuildingBlockEntries("INTRO") _
  .Insert _
  Where:=selection.Range, _
  RichText:=True
End With
doc.Activate
Set doc = Nothing
Set objWord = Nothing
 
I was able to add the autotext, but how can I add multiple autotext 1 after the other?

Code:
   Dim objWord As Word.Application
  Dim docWord As Word.Document
  Dim WordHeaderFooter As HeaderFooter
  
  Set objWord = CreateObject("Word.Application")
  
  objWord.Visible = True
  Set docWord = objWord.Documents.Open("C:\Users\yygh98\Desktop\TEMPLATE.dot")
  
  docWord.AttachedTemplate.AutoTextEntries("INTRO").Insert _
   Where:=docWord.Range, RichText:=True
 

Users who are viewing this thread

Back
Top Bottom