473,568 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fill Word-template fields

Hello,

I've created a Word-template for a letter. I've made some fields in the
template (such as 'customer number', 'name', ...) as follows: insert
field - DocVariabele with name 'customer number' and 'name'. Now I want
to fill these fields from my application and print them:
Dim myWord As New Word.Applicatio n
myWord.Document s.Add("c:\templ ate.dot")
'fill the fields
'...
'print
myWord.ActiveDo cument.PrintOut ()
myWord.Quit(Wor d.WdSaveOptions .wdDoNotSaveCha nges)
So what code is needed before I print the document to fill my template
fields?

Thanks

Steven
Nov 21 '05 #1
5 7970
You can read/write the document variables collection. Something like this:
(might not be exactly like this!):
For i as Integer = 0 To TheDocument.Var iables.Count
Select Case theDocument.Var iables.Item(i). Name

Case "a_name"

theDocument.Var iables.Item(i). Value = "test"

End Select
Next
Something to note: make sure you clean up all references correctly :)
"steven" <us**@example.n et> wrote in message
news:e6******** ******@TK2MSFTN GP15.phx.gbl...
Hello,

I've created a Word-template for a letter. I've made some fields in the
template (such as 'customer number', 'name', ...) as follows: insert
field - DocVariabele with name 'customer number' and 'name'. Now I want to
fill these fields from my application and print them:
Dim myWord As New Word.Applicatio n
myWord.Document s.Add("c:\templ ate.dot")
'fill the fields
'...
'print
myWord.ActiveDo cument.PrintOut ()
myWord.Quit(Wor d.WdSaveOptions .wdDoNotSaveCha nges)
So what code is needed before I print the document to fill my template
fields?

Thanks

Steven

Nov 21 '05 #2
"steven" <us**@example.n et> schrieb:
Dim myWord As New Word.Applicatio n
myWord.Document s.Add("c:\templ ate.dot")
'fill the fields
'...
'print
myWord.ActiveDo cument.PrintOut ()
myWord.Quit(Wor d.WdSaveOptions .wdDoNotSaveCha nges)

So what code is needed before I print the document to fill my template
fields?


\\\
Option Strict Off
..
..
..
Dim WordApp As Object = CreateObject("W ord.Application ")
Dim WordDoc As Object = WordApp.Documen ts.Open("C:\Hal lo.doc")
WordDoc.FormFie lds("Text1").Re sult = "Bla"
WordDoc.Save()
WordDoc.Close()
WordApp.Quit()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3
Herfried K. Wagner [MVP] wrote:
"steven" <us**@example.n et> schrieb:
Dim myWord As New Word.Applicatio n
myWord.Document s.Add("c:\templ ate.dot")
'fill the fields
'...
'print
myWord.ActiveDo cument.PrintOut ()
myWord.Quit(Wor d.WdSaveOptions .wdDoNotSaveCha nges)

So what code is needed before I print the document to fill my template
fields?

\\\
Option Strict Off
.
.
.
Dim WordApp As Object = CreateObject("W ord.Application ")
Dim WordDoc As Object = WordApp.Documen ts.Open("C:\Hal lo.doc")
WordDoc.FormFie lds("Text1").Re sult = "Bla"
WordDoc.Save()
WordDoc.Close()
WordApp.Quit()
///


Thanks for the tip, but my document doesn't seem to have any items in
the 'FormFields' property, and neither does the 'Fields' and the
'Variables' property. Are there any other properties to look at?

Thanks in advance.

Steven
Nov 21 '05 #4
Robin Tucker wrote:
You can read/write the document variables collection. Something like this:
(might not be exactly like this!):
For i as Integer = 0 To TheDocument.Var iables.Count
Select Case theDocument.Var iables.Item(i). Name
Case "a_name"
theDocument.Var iables.Item(i). Value = "test"
End Select
Next
Something to note: make sure you clean up all references correctly :)


Thanks for the tip, but my document doesn't seem to have any items in
the 'Variables' property, and neither does the 'Fields' and the
'FormFields' property. Are there any other properties to look at?

Thanks in advance.

Steven
Nov 21 '05 #5
Thanks, that worked (eventually) great.

Steven

Herfried K. Wagner [MVP] wrote:
"steven" <us**@example.n et> schrieb:
Dim myWord As New Word.Applicatio n
myWord.Document s.Add("c:\templ ate.dot")
'fill the fields
'...
'print
myWord.ActiveDo cument.PrintOut ()
myWord.Quit(Wor d.WdSaveOptions .wdDoNotSaveCha nges)

So what code is needed before I print the document to fill my template
fields?

\\\
Option Strict Off
.
.
.
Dim WordApp As Object = CreateObject("W ord.Application ")
Dim WordDoc As Object = WordApp.Documen ts.Open("C:\Hal lo.doc")
WordDoc.FormFie lds("Text1").Re sult = "Bla"
WordDoc.Save()
WordDoc.Close()
WordApp.Quit()
///

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2109
by: Maurice Mertens | last post by:
Hi all, In VB.NET you can set the DropDownStyle for a combobox to 'DropDown' or 'DropDownList'. When you set it to DropDownList, it supports auto-fill. But when you set it to 'DropDown', the auto-fill support is gone. How can I get auto-fill on a combobox with a dropdownstyle 'DropDown'? --
5
6200
by: Joe C | last post by:
I'm a hobbiest, and made the forray into c++ from non-c type languages about a year ago. I was "cleaning up" some code I wrote to make it more "c++ like" and have a few questions. I'm comfortable using new/delete when dealing with arrays, and, so-far haven't used the STL (eg vectors) very much when dealing with POD. I'm using a class to...
4
1833
by: MLH | last post by:
I have tblFiles with and fields. DLookUp("","tblFiles","=22") returns "c:\EMLfiles\00002.eml". The return string is a pointer to a dot-eml file in c:\EMLfiles. The dot-eml file was created in MS Outlook Express through its File - Save As facility. Each dot-eml file contains a small paragraph of text and a small (8k - 22k) graphic file....
4
3742
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure and username, password etc will be exactly the same for each server, the only thing that will change is the server name. Idealy I would like to get...
30
3284
by: Raymond Hettinger | last post by:
Proposal -------- I am gathering data to evaluate a request for an alternate version of itertools.izip() with a None fill-in feature like that for the built-in map() function: >>> map(None, 'abc', '12345') # demonstrate map's None fill-in feature The motivation is to provide a means for looping over all data elements
12
2072
by: Raymond Hettinger | last post by:
I am evaluating a request for an alternate version of itertools.izip() that has a None fill-in feature like the built-in map function: >>> map(None, 'abc', '12345') # demonstrate map's None fill-in feature The movitation is to provide a means for looping over all data elements when the input lengths are unequal. The question of the...
0
1244
by: sweetpotatop | last post by:
Hello, I have a locked Word document (save as XML) in which I need to fill out the bookmark through ASP.NET And part of the xml is shown below: <aml:annotation aml:id="0" w:type="Word.Bookmark.Start" w:name="ContactName" /> <w:r> <w:rPr>
6
5443
by: Cliff72 | last post by:
I need to fill in the nulls in the batch field the value from the record immediately preceding the null one ie replace the nulls with the preceding value until I hit a record with a value in it--then hold the next value through the next set of nulls, and so on. See example below: I wanna copy down batch "IMR138" in record ID 1, all the way...
8
1987
by: sfauchille | last post by:
Hello, I have to fill a treeview with data in a text file text file A.B.C.D.Var1 A.B.C.D.var2 A.B.A.Var1 B.A.C.var2 B.C.D.var3
9
8134
by: Eric Lindsay | last post by:
How do you provide a consistent gradient fill as a background in a liquid layout? If I make a gradient fill image say 1000 pixels wide (and repeat it down the page) to suit a typical computer display, then only a small portion of the gradient will show if the viewpoint is a smaller PDA or phone display. On the other hand, if viewed full...
0
7692
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7913
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7659
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6274
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.