Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    3 Star Lounger
    Join Date
    Oct 2002
    Location
    Houston, Texas, USA
    Posts
    303
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print Word Document (Office 2004)

    I have a MS Outlook form where I print a MS Word template. I keep coming up with the following error: MS Word was unable to read this document. It may be corrupt. Tryone of the following: open and repair file, open the file with the Text Recovery converter....

    '-=-=-=-=-=-=-=-=-=-
    'Printing function
    ' - opening a Word template with bookmarks
    ' - read bookmarks list from template and match with the field names in Outlook form
    ' - value in form is that populated to the Word doc for auto-printing
    ' - prompt user for closing Word when printing is done.
    ' - Save word as C:deletme.doc before exiting Word.
    ' 8/21/98 Leng Ho
    ' 9/16/98 modified to include remove save C:deletme.doc function
    ' remove visibility of Word
    ' correct problem by using Item.UserProperties.find(strField).value
    '
    'Modified by Daniel Reyes

    Dim strTemplate
    Dim objWord
    Dim objDocs
    Dim PageRange
    Dim strField
    Dim strField1

    Sub cmdBookmarks_Click

    Set objWord = CreateObject("Word.Application")

    ' Put the name of your Word template that contains the bookmarks
    strTemplate = "PCConversion2.dot"

    ' Location of Word template; could be on a shared LAN
    strTemplate = "tabsnasdatabase$edgarnewcigars" & strTemplate

    Set objDocs = objWord.Documents
    objDocs.Add strTemplate
    set mybklist = objWord.ActiveDocument.Bookmarks


    For counter = 1 to mybklist.count
    strField = objWord.ActiveDocument.Bookmarks(counter)
    objWord.ActiveDocument.Bookmarks(strField).Select
    strField1 = Item.UserProperties.find(strField).value
    If strField1 = True then
    strField1 = "Yes"
    ElseIf strField1 = False then
    strField1 = " "
    End If
    objWord.Selection.TypeText Cstr(strField1)
    Next
    objWord.PrintOut Background = True
    objWord.Quit(0)

    End Sub
    '-=-=-=-=-=-=-=-=--

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Document (Office 2004)

    What happens if you try to create a new document based on this template interactively in Word?

    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17> Office 2004?

  3. #3
    3 Star Lounger
    Join Date
    Oct 2002
    Location
    Houston, Texas, USA
    Posts
    303
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Document (Office 2004)

    1. Ooops...That should say Office 2003.
    2. have tried twice to create the template from scratch. And for now I am getting the same results.
    a. I deleted the original documents, created the new one and saved it. - save results.
    b. I also tried to save the file under a different name and rename the file in the code. - same results.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Document (Office 2004)

    But does the template work as expected within Word, when you activate the New Document task pane, click 'On my computer...', select the template and click OK?

  5. #5
    3 Star Lounger
    Join Date
    Oct 2002
    Location
    Houston, Texas, USA
    Posts
    303
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Document (Office 2004)

    Yes, going through these steps the document comes up fine.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Document (Office 2004)

    Sorry, no idea then. Let's hope someone else comes up with a suggestion.

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Print Word Document (Office 2004)

    If you debug, which line causes the error -- the .Add ?

    Immediately after your assignment where you create the full path, try this:

    MsgBox Dir(strTemplate)

    Needless to say, if the messagebox is blank, your path is incorrect.

    ---

    Separately, I think it would be better to change your variables around a bit.

    Dim docNew as Word.Document
    Set docNew = objWord.Documents.Add strTemplate

    Change all instances of objWord.Activedocument to docNew

    That's not to say Outlook will necessarily lose track of the fact that you want ActiveDocument to refer to your newly created document, but <img src=/w3timages/censored.gif alt=censored border=0> happens. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  8. #8
    3 Star Lounger
    Join Date
    Oct 2002
    Location
    Houston, Texas, USA
    Posts
    303
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Document (Office 2004)

    Not sure how to do this

    Dim docNew as Word.Document
    Set docNew = objWord.Documents.Add strTemplate

    to

    Dim docNew Word.Document

    Sub cmdBookmarks_Client
    Set DocNew = objWord.Document.Add strTemplate



    thank yo

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Document (Office 2004)

    The second code fragment doesn't make sense. What are you trying to do?

  10. #10
    3 Star Lounger
    Join Date
    Oct 2002
    Location
    Houston, Texas, USA
    Posts
    303
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Document (Office 2004)

    I am have to many problems with this script. I want to use my msOutlook form to capture the data and then press a cmd button to print some of the data to the attached word document using a template.

    I keep getting errors that the doc is corrupted. I created the doc over several times and tried repair and convert. Nothing is working.. can someone think of a better wayto print? Just remember that I am not a programmer, just a tinker that hopes it will work.


    Thank you

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Document (Office 2004)

    I don't see anything wrong with the document. Try this version:

    Sub cmdBookmarks_Click()
    Dim strTemplate
    Dim objWord
    Dim objDocs
    Dim newDoc
    Dim PageRange
    Dim strField
    Dim strField1
    Dim mybklist
    Dim counter
    Set objWord = CreateObject("Word.Application")
    ' Put the name of your Word template that contains the bookmarks
    strTemplate = "PCConversion2.dot"

    ' Location of Word template; could be on a shared LAN
    strTemplate = "tabsnasdatabase$edgarnewcigars" & strTemplate

    Set objDocs = objWord.Documents
    Set newDoc = objDocs.Add(strTemplate)
    Set mybklist = newDoc.Bookmarks

    For counter = 1 To mybklist.Count
    strField = mybklist(counter)
    strField1 = Item.UserProperties.Find(strField).Value
    If strField1 = True Then
    strField1 = "Yes"
    ElseIf strField1 = False Then
    strField1 = " "
    End If
    mybklist(counter).Range.Text = CStr(strField1)
    Next counter

    newDoc.PrintOut Background:=True
    objWord.Quit SaveChanges:=False
    End Sub

  12. #12
    3 Star Lounger
    Join Date
    Oct 2002
    Location
    Houston, Texas, USA
    Posts
    303
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Document (Office 2004)

    Getting "Expected end of statement Line 760" - Next Counter is the line.

    For counter = 1 To mybklist.Count
    strField = mybklist(counter)
    strField1 = Item.UserProperties.Find(strField).Value
    If strField1 = True Then
    strField1 = "Yes"
    ElseIf strField1 = False Then
    strField1 = " "
    End If
    mybklist(counter).Range.Text = CStr(strField1)
    Next counter this is line 760

    newDoc.PrintOut Background:=True
    objWord.Quit SaveChanges:=False

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Document (Office 2004)

    Try changing

    Next counter

    back to

    Next

  14. #14
    3 Star Lounger
    Join Date
    Oct 2002
    Location
    Houston, Texas, USA
    Posts
    303
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Document (Office 2004)

    The script works fine.

    Still getting erros that the file is corrupted. at line - set newDoc = objDocs.Add(strTemplate)

    Going look more into this corrupted file. I can open both the DOC and DAT files.

    Thanks for you help.

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Document (Office 2004)

    The file you attached didn't cause any problems when I ran the code.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •