|
-
Jan 3rd, 2006, 10:25 PM
#1
Thread Starter
Addicted Member
VBA and word
Hii all
i have a prob, i have created a word template with some Bookmark on it and i just want to take the values from VB an put it in the word template and get a printout and also save it as different name,
but when i tried it out the that has the bookmark is replacing the values and is not saving as new file how should i work...?
-
Jan 3rd, 2006, 10:50 PM
#2
Re: VBA and word
Use a normal .doc file instead of a .dot file, and then call the .SaveAs("Filename") method of your document object. Actual templates are a pain to deal with IMHO (even when you aren't coding to them). You can print it out by calling the .PrintOut method.
-
Jan 3rd, 2006, 11:14 PM
#3
Thread Starter
Addicted Member
Re: VBA and word
okay but what if i justr want to take the values from the vb and then put them on a word file and then just get a print out but dont want to save it how to do that..?
-
Jan 3rd, 2006, 11:30 PM
#4
Re: VBA and word
 Originally Posted by amit_m04
okay but what if i justr want to take the values from the vb and then put them on a word file and then just get a print out but dont want to save it how to do that..?
Something like this:
VB Code:
Private Sub FillDocAndPrint()
Dim oDoc As Word.Document, oWord As Word.Application
Set oWord = New Word.Application
Set oDoc = oWord.Documents.Open("Template.doc")
With oDoc
.Bookmarks("One").Range.Text = "Foo"
.Bookmarks("Two").Range.Text = "Bar"
End With
oDoc.PrintOut
oDoc.Close (wdDoNotSaveChanges)
Do While oWord.BackgroundPrintingStatus <> 0
DoEvents 'Wait until the print is done.
Loop
oWord.Quit
End Sub
Last edited by Comintern; Jan 3rd, 2006 at 11:32 PM.
Reason: Fix screwy VBCode tag indents :-/ (gave up)
-
Jan 4th, 2006, 07:53 AM
#5
Re: VBA and word
Moved to office development
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|