473,721 Members | 2,067 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 7976
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
2121
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
6239
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 dump files into. The class puts the file data into a 32-bit array, then offers both 32-bit and char*...
4
1837
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. I'm seeking mechanism to read and interpret the dot-eml file
4
3751
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 the server names from a seperate dataset so there could be any number of servers, allthough in...
30
3305
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
2087
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 day is whether that is both a common need and a good approach to real-world problems. The answer to...
0
1253
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
5451
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 to ID 10. Then copy down batch "7138" all the way to ID 20 and so on....
8
1994
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
8142
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 screen on a 1920 pixel wide display, I would run out of gradient on one or both sides of the page....
0
8736
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9373
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9227
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9081
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6676
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5992
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4497
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4761
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3206
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.