Results 1 to 5 of 5

Thread: VBA and word

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    179

    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...?

  2. #2
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    179

    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..?

  4. #4
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: VBA and word

    Quote 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:
    1. Private Sub FillDocAndPrint()
    2.  
    3.     Dim oDoc As Word.Document, oWord As Word.Application
    4.    
    5.     Set oWord = New Word.Application
    6.     Set oDoc = oWord.Documents.Open("Template.doc")
    7.    
    8.     With oDoc
    9.         .Bookmarks("One").Range.Text = "Foo"
    10.         .Bookmarks("Two").Range.Text = "Bar"
    11.     End With
    12.    
    13.     oDoc.PrintOut
    14.     oDoc.Close (wdDoNotSaveChanges)
    15.    
    16.     Do While oWord.BackgroundPrintingStatus <> 0
    17.         DoEvents        'Wait until the print is done.
    18.     Loop
    19.    
    20.     oWord.Quit
    21.        
    22. End Sub
    Last edited by Comintern; Jan 3rd, 2006 at 11:32 PM. Reason: Fix screwy VBCode tag indents :-/ (gave up)

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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
  •  



Click Here to Expand Forum to Full Width