Home > Archive > Visual Basic > March 2006 > Word and VB
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| How can I populate a Word document from within VB? More like a mail merge,
but in reverse. The word document will be a pre-defined form with fields to
be populated. I want the user to be able to click on a button when viewing a
record, retrieve the word document, populate the fields and print the
document if they choose to. The VB application reads data from a SQL database.
Thanks
Emma
| |
|
| Stick some bookmarks in your Word doc. Load a copy of the doc then replace
the bookmarks with your user datafields, then print.
Bod
"Emma" wrote:
> How can I populate a Word document from within VB? More like a mail merge,
> but in reverse. The word document will be a pre-defined form with fields to
> be populated. I want the user to be able to click on a button when viewing a
> record, retrieve the word document, populate the fields and print the
> document if they choose to. The VB application reads data from a SQL database.
>
> Thanks
> Emma
>
| |
|
| Can you please point me to some sample code on doing this?
Thanks
Emma
"Bod" wrote:
[color=darkred]
> Stick some bookmarks in your Word doc. Load a copy of the doc then replace
> the bookmarks with your user datafields, then print.
> Bod
>
>
> "Emma" wrote:
>
| |
| Jan Hyde 2006-03-29, 6:56 pm |
| Emma <Emma@discussions.microsoft.com>'s wild thoughts were
released on Wed, 29 Mar 2006 06:30:02 -0800 bearing the
following fruit:
>How can I populate a Word document from within VB? More like a mail merge,
>but in reverse. The word document will be a pre-defined form with fields to
>be populated. I want the user to be able to click on a button when viewing a
>record, retrieve the word document, populate the fields and print the
>document if they choose to. The VB application reads data from a SQL database.
>
Sounds exactly like mail merge, are reason you don't want to
do it that way?
Jan Hyde (VB MVP)
--
So I was in Tesco's and I saw this man and woman wrapped in a barcode.
I said "Are you two an item?"
| |
|
| I want to use the VB application because the data required to populate the
Word document is already being displayed in the VB form and the data is
pulled from multiple tables in a database.
Is there a way of running mail merge from within VB and passing it the data?
One other method I was thinking of doing is using bookmarks in word and
calling up the document from within the VB application to populate the
document. I just have to find an example of how it is done.
Thanks
Emma
"Jan Hyde" wrote:
> Emma <Emma@discussions.microsoft.com>'s wild thoughts were
> released on Wed, 29 Mar 2006 06:30:02 -0800 bearing the
> following fruit:
>
>
> Sounds exactly like mail merge, are reason you don't want to
> do it that way?
>
>
>
> Jan Hyde (VB MVP)
>
> --
> So I was in Tesco's and I saw this man and woman wrapped in a barcode.
> I said "Are you two an item?"
>
>
| |
|
|
"Emma" <Emma@discussions.microsoft.com> wrote in message
news:5646F58D-6280-47DA-BE67-3FD748B7055B@microsoft.com...
> How can I populate a Word document from within VB? More like a mail merge,
> but in reverse. The word document will be a pre-defined form with fields
to
> be populated. I want the user to be able to click on a button when viewing
a
> record, retrieve the word document, populate the fields and print the
> document if they choose to. The VB application reads data from a SQL
database.
>
> Thanks
> Emma
>
There is an interesting Using Word as Report Generator document, which
covers many of the issues, at this site...
http://www.controlcenter.com/FreeCo...37/Default.aspx
Which also notes that the best tool for learning the object model is
creating a VBA/Macro solution in Word first - then export it to VB.
Some code that uses bookmarks...
"MS Word Automation"
http://www.vbmysql.com/samplecode
If using VB6 or below... using a table
http://experts.about.com/q/Visual-B...-table-MS-3.htm
The MSDN Office development website used to be one of the first stops. But
MS has hidden away most of the old classic VB samples, in favorite of
promoting .Net solutions. However, .Net does automation through the same COM
Office Object Model (using interopt), so if you can weed through the PIA
crap, etc. You will find the actual code to be decent examples. (I think
most are just quick rewrites of the original solutions.)
For the specific odd issue, searching the newsgroups is your best bet for
answers. The last good book on Word Automation (Word VBA by Wrox) is out of
print.
[You may safely ignore the following... <g>]
Don't know why there has never been a good Word automation book, since Woody
Leonhard's "Hacker's Guide to Word for Windows" (1993). The next best book
Wrox's Word VBA is out of print. There are tons of books for Excel and
Access, but Word has always been slighted. <?>
Somebody missed out on a chance to make a buck.
[\end blog]
-ralph
| |
| Jan Hyde 2006-03-30, 3:55 am |
| Emma <Emma@discussions.microsoft.com>'s wild thoughts were
released on Wed, 29 Mar 2006 08:20:02 -0800 bearing the
following fruit:
>I want to use the VB application because the data required to populate the
>Word document is already being displayed in the VB form and the data is
>pulled from multiple tables in a database.
>
>Is there a way of running mail merge from within VB and passing it the data?
There is, we write out the data to a text file, open the
document and tell it to do the mail merge. You may well be
able to do it without the text document though. I'm no
expert in this area.
>One other method I was thinking of doing is using bookmarks in word and
>calling up the document from within the VB application to populate the
>document. I just have to find an example of how it is done.
You could, but it sounds a lot like a poor mans mail merge.
However if you want an example, then start recording a
macro, do it manually, stop the macro and look at the code,
you should be able to use or adapt that code for use in your
VB app.
J
[color=darkred]
>Thanks
>Emma
>
>
>"Jan Hyde" wrote:
>
Jan Hyde (VB MVP)
--
I bought a no-stick frying pan, which is superflous as I do not eat sticks anyway.
(Jimmy Snibbler)
| |
|
| I would have though MailMerge was the poor solution. I use Mailmerge if I
need lots of documents like remittances or statements, but for 1 document it
seems overkill. Writing the data to a table or file only to read it back in
during the merge, resetting the doc data source for each user if using
separate files, what a pain. Just stick some bookmarks in the doc where you
want the data. Then open the doc(template), replace Doc.Bookmarks("<name>")
with required data, then print the doc.
"Jan Hyde" wrote:
> Emma <Emma@discussions.microsoft.com>'s wild thoughts were
> released on Wed, 29 Mar 2006 08:20:02 -0800 bearing the
> following fruit:
>
>
> There is, we write out the data to a text file, open the
> document and tell it to do the mail merge. You may well be
> able to do it without the text document though. I'm no
> expert in this area.
>
>
> You could, but it sounds a lot like a poor mans mail merge.
> However if you want an example, then start recording a
> macro, do it manually, stop the macro and look at the code,
> you should be able to use or adapt that code for use in your
> VB app.
>
> J
>
>
>
> Jan Hyde (VB MVP)
>
> --
> I bought a no-stick frying pan, which is superflous as I do not eat sticks anyway.
>
> (Jimmy Snibbler)
>
>
|
|
|
|
|