Jeffery B Paarsa was telling us:
Jeffery B Paarsa nous racontait que :
Hi Jean,
Yes I have 5-6 different Word templates that I would like to use them
and print 5-6 different Word Documents from them. So the answer to
your first question is to produce Word documents from Word Templates.
No there are no requirements to save the documents after printing.
Just to populate the data fields captured from the VB Form put them
on Bookmarked TextFields and then print it. Captured data from VB
Form field screen, will be used to access database to extract more
data for populating the TextFields on the Word Templates to print the
Word Documents "Future plan not right now".
Yes the different Documents printed from these 5-6 templates will be
used only once and it will be printed once and does not get saved.
By Silent mode I mean that I do not want the user even see the "Word
document Windows" to be popped up and opened.... Just on the back
ground "invisible, silent mode" populate the data on the
TextFields/Bookmarked defined on the Templates print the Documents
one after another.
I just received my Visual Studio Pro 2005 today... Haven't installed
it.
You could do this from VBA... But since you seem bent on doing it with VS...
transfer this VBA code to VB6. If you use VB.Net, more adjustments will be
needed.
Also, before printing the 4-5 documents, I would make sure that I asked the
user to confirm whatever it is they have typed. It would be frustrating as a
user to go to the printer and see you have a typo in all documents...
For this purpose, you could create a message box (see MsgBox in your VB
manuals), or, you could replace all Input Boxes and the message box with a
userform.
'_______________________________________
Option Explicit
Private strUserName As String
Private strUserOther As String
'_______________________________________
Sub Main()
Const myTemplate1 As String = "C:\Templates\Template1.dot"
Const myTemplate2 As String = "C:\Templates\Template2.dot"
Const myTemplate3 As String = "C:\Templates\Template3.dot"
Const myTemplate4 As String = "C:\Templates\Template4.dot"
Const myTemplate5 As String = "C:\Templates\Template5.dot"
Dim wdApp As Word.Application
strUserName = InputBox("What is your name?", "Name", "Type Here")
If Trim(strUserName) = "" Then 'User clicked Cancel or erased all content
Exit Sub
End If
strUserOther = InputBox("What is Other stuff?", "Stuff", "Type Here")
If Trim(strUserOther) = "" Then 'User clicked Cancel or erased all content
Exit Sub
End If
Set wdApp = CreateObject("Word.Application")
CreateDoc wdApp, myTemplate1
CreateDoc wdApp, myTemplate2
CreateDoc wdApp, myTemplate3
CreateDoc wdApp, myTemplate4
CreateDoc wdApp, myTemplate5
wdApp.Quit
Set wdApp = Nothing
End Sub
'_______________________________________
'_______________________________________
Private Sub CreateDoc(myApp As Word.Application, _
strTemplate As String)
Dim wdDoc As Word.Document
Set wdDoc = myApp.Documents.Add(strTemplate, False, wdNewBlankDocument,
False)
With wdDoc
.Bookmarks("NameBookmark").Range.Text = strUserName
.Bookmarks("StuffBookmark").Range.Text = strUserOther
.PrintOut
.Close wdDoNotSaveChanges
End With
End Sub
'_______________________________________
I could have used an array to store the template names, but since you only
have 4-5, it is not much trouble to do it as I did.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org