Passing a variable?

A

Angyl

It's me again.

And I continue to work refining the work I've already done for the office.

Now I want to make it easier on my sales people and I need one piece of code
to make that work.

I want to make a document with form fields that has a macro at the end.
This document will ask the sales person to enter basic client information and
then:

Open another document (template) fill in the information in bookmarked
fields and print it...close the document.

Open a DIFFERENT document (template), fill in the information in bookmarked
fields and print it...close the document.

So on and so forth, but for several of the documents, I want it to print X
number of copies, where X has been inputted into one of the fields by the
salesperson.

I know how to do all of this (I think) except that last part, getting X to
be the number of copies that are printed.
 
D

Doug Robbins - Word MVP

Don't like the sound of what you are doing, but in answer to your specific
question:

Dim X As Long
X = ActiveDocument.FormFields("numberofcopies").result
ActiveDocument.PrintOut Copies:=X

This will print the document containing the formfields. If it is some other
document that you want to print, you will need to make the proper reference
to it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Angyl

This should do it, Doug, thanks!

Doug Robbins - Word MVP said:
Don't like the sound of what you are doing, but in answer to your specific
question:

Dim X As Long
X = ActiveDocument.FormFields("numberofcopies").result
ActiveDocument.PrintOut Copies:=X

This will print the document containing the formfields. If it is some other
document that you want to print, you will need to make the proper reference
to it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Angyl

IT WORKS!!

mostly...

I thought I knew how to pass the boomark names into the new document to fill
in the form before completing it but it's not working

response = MsgBox("Print Set Up Paperwork Now?", vbQuestion + vbYesNo)
If response = vbYes Then
Dim X As Long
X = ActiveDocument.FormFields("Employees").Result
Documents.Open ("C:\Documents and Settings\tallen\Application
Data\Microsoft\Templates\Test.dot")
With ActiveDocument
.FormFields("ClientName").Result = ClientName
End With
ActiveDocument.PrintOut Copies:=X
ActiveDocument.Close

This code currently prints out the required # of documents but the field is
empty.

Also the ActiveDocument.Close doesn't work. Says the command is
unavailable, perhaps because the printing is going on?
 
H

Helmut Weber

Hi Angyl,

try setting PrintBackground to false.

Or check Application.BackgroundPrintingStatus
in a loop.
Not recommended.

Besides that,
opening a template instead of creating a new doc
based on a template, doesn't seem a good idea to me.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top