Results 1 to 7 of 7
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211

    Automating Word from VBScript


    Hi,

    Not sure if this forum is the correct place, please advise if there is a better forum.

    I'm trying to print an envelope by automating MS Word. This works fine for me in Access VBA, but having problems with VBScript. Here is my code, modified to work in VBScript:

    Code:
    Dim wd, Doc
    Set wd = CreateObject("Word.Application")
    wd.Visible = False
    Set Doc = wd.Documents.Add
    Doc.Envelope.PrintOut , fullAddress, , , retAddress
    Doc.Close False
    Set Doc = Nothing
    Set wd = Nothing
    Note fullAddress and retAddress were set previously, and contain text and VbCrLf's.

    The PrintOut method results in a type mismatch error.
    The documentation says:

    expression
    .PrintOut (ExtractAddress, Address, AutoText, OmitReturnAddress, ReturnAddress, ReturnAutoText, PrintBarCode, PrintFIMA, Size, Height, Width, FeedSource, AddressFromLeft, AddressFromTop, ReturnAddressFromLeft, ReturnAddressFromTop, DefaultFaceUp, DefaultOrientation, PrintEPostage, Vertical, RecipientNamefromLeft, RecipientNamefromTop, RecipientPostalfromLeft, RecipientPostalfromTop, SenderNamefromLeft, SenderNamefromTop, SenderPostalfromLeft, SenderPostalfromTop)

    Note that Address is the second parameter and ReturnAddress is the 5th parameter. VBScript doesn't allow named parameters, so I had to use the commas to place the needed parameters in the correct position.

    If I move the return address to the 4th position by removing a comma, it all works. I understand the return address won't print because I did not send it in the proper position. But why do I get a type mismatch with it in the right position?

    Any ideas what is going wrong?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    The doc may not have an envelope in it.
    did you open a file (doc) with an envelope in it?

  3. #3
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by ranman256 View Post
    The doc may not have an envelope in it.
    did you open a file (doc) with an envelope in it?
    Thanks for the reply, but it does have an envelope. The code creates a new document then adds an envelope to it. This code works properly in Access.
    Also, the envelope does in fact print out if I move the return address up higher in the field list by deleting the comma just before the return address. Of course, this puts the return address into a boolean field called OmitReturnAddress. I can see why this causes the return address to not print. But the envelope does in fact print out. But if I put the return address in the correct position in the field list, it causes the type mismatch error.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Do you have a comma in the fields, before returnaddress?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Welshgasman View Post
    Do you have a comma in the fields, before returnaddress?
    Yes, I do. Compare the program statement with the example of what fields are available from the documentation. Both of these are in my original post.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No! :-(
    I mean does fullAddress have a comma in it?
    That might confuse word?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Welshgasman View Post
    No! :-(
    I mean does fullAddress have a comma in it?
    That might confuse word?
    Oh, sorry. The addresses do indeed have commas as expected. However, I don't think that's the issue, because the destination address prints properly, commas and all.
    Both addresses have commas between the city & state.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Automating Word MailMerge Won't Merge Images
    By RMittelman in forum Programming
    Replies: 4
    Last Post: 02-17-2021, 08:58 AM
  2. Error in Access VBA Automating Word Merge from Excel
    By RMittelman in forum Programming
    Replies: 4
    Last Post: 01-20-2021, 05:56 PM
  3. VBscript. combining Getfile with Oshell.Environment
    By redbull in forum Programming
    Replies: 1
    Last Post: 03-22-2016, 10:19 AM
  4. vbscript open access db and execute sub
    By Auto in forum Programming
    Replies: 1
    Last Post: 04-22-2015, 01:29 PM
  5. Replies: 2
    Last Post: 09-15-2014, 01:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums