Results 1 to 15 of 15

Thread: Print settings - API?

  1. #1

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Print settings - API?

    Hi,

    I need a macro that changes an active documents print settings for MS Word 97 so that the following is selected:

    - 1 sided printing
    - Page 1 Tray 1
    - Page 2 Tray 2
    - Page 3+ Tray 4

    Is this possible?

    thanks
    Last edited by rocket0612; Mar 6th, 2006 at 02:46 PM.
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  2. #2
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Print settings

    I know that you can use VBA code select the printer to use for a specific job, but to go beyond that and select particular features of the printer will probably require Windows API calls (?). At least I couldn't figure out any other way to do it. Maybe someone with API experience can help. You may have to repost this with "API" in the title.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  3. #3

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Re: Print settings - API?

    thanks for the reply, haven't a clue what API is but have renamed the title!
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  4. #4

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Re: Print settings - API?

    I have found this sample code but it errors when it gets to ' .DefaultTray = "Tray 2"':

    VB Code:
    1. Dim sCurrentPrinter As String
    2.   sCurrentPrinter = ActivePrinter
    3.     wrd.ActivePrinter = "\\BTBEAPAPP03\PBTBEA00001M"
    4.     wrd.With Options
    5.         .DefaultTray = "Tray 2"
    6.     End With
    7.     Application.PrintOut FileName:=""
    8.     wrd.With Options
    9.         .DefaultTray = "Use printer settings"
    10.     End With
    11.     ActivePrinter = sCurrentPrinter

    any suggestions?

    thanks
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Print settings - API?

    Dont use the text property - "Tray 2"
    VB Code:
    1. 'Const wdPrinterDefaultBin = 0
    2.     'Const wdPrinterUpperBin = 1
    3.     'Const wdPrinterLowerBin = 2
    4.     'Const wdPrinterMiddleBin = 3
    5.     'Const wdPrinterManualFeed = 4
    6.     Options.DefaultTrayID = wdPrinterUpperBin
    7.     ActiveDocument.PrintOut
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Re: Print settings - API?

    thanks for the reply,

    I now have this:

    VB Code:
    1. Dim sCurrentPrinter As String
    2. sCurrentPrinter = ActivePrinter
    3.     wrd.ActivePrinter = "\\BTBEAPAPP04\PBTBEA00004M"
    4.     Const WdPrinterLowerbin = 2
    5.     wrd.Options.DefaultTrayID = WdPrinterLowerbin
    6.     wrd.Application.PrintOut FileName:=""

    however, it isn't selecting the tray.

    Maybe I am along the wrong lines here. The problem is, the document when opened and printed automatically prints out on tray 1 for the first 2 pages, then tried to print the rest from the side feed but I can't figure out how to change this. When I go into print properties, it just has the paper source as auto so I think it has the print properties stored somewhere to default to the settings above?

    thanks
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Print settings - API?

    Did you try the other constants I posted in my code? There are 15 different constants in all but these 5 are the most relevant.

    wdPrinterDefaultBin

    Or

    wdPrinterManualFeed
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Re: Print settings - API?

    thanks robdog, yeah, played abut and it seems to be working better, just need to figure which constants to use, we have big multifuntional printers with 4 trays and a side large bin, figured out the large side bin is wdPrinterLargeCapacityBin and got it printing from there. so, just a little playing about needed!

    How can I get it now to only print page1 from one try, page 2 from another & the rest from another as the code I have prints it all from the same tray?

    many thanks, I appreciate the help as this was driving me crazy
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Print settings - API?

    VB Code:
    1. Options.DefaultTrayID = wdPrinterLargeCapacityBin
    2.     ActiveDocument.PrintOut , , Range:=wdPrintFromTo, From:=1, To:=1
    3.     Options.DefaultTrayID = wdPrinterLowerBin
    4.     ActiveDocument.PrintOut , , Range:=wdPrintFromTo, From:=2, To:=2
    5.     Options.DefaultTrayID = wdPrinterUpperBin
    6.     ActiveDocument.PrintOut , , Range:=wdPrintFromTo, From:=3, To:=5
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Print settings - API?

    RobDog ...

    Where did you ever pick up all of this minutiae/trivia ??? Are you an escapee from Redmond?

    I tried to rate your post (positively?) but the system is tired of my giving you credit.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Print settings - API?

    No, but I think I will be going over there next year. I'll say hi to Bill for you.

    I guess it just comes from the love of Office and automating it. I have learned over the years how the object library is all put together and what it mostly consists of so with a little searching I can find most stuff fast (if I dont remember it). Then its just testing what the poster needs solving and post to vbf.

    Plus, I have many programs and utilities I have written over the years so I can usually pull some code or functions from them and create a sample.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Re: Print settings - API?

    thanks Robdog,

    I've worked out what paper trays I need.

    I'm now getting a run-time error on the line:

    VB Code:
    1. wrd.ActiveDocument.PrintOut , , Range:=wdPrintFromTo, From:=1, To:=1

    Run-Time error '5148'
    the number must be between -32765 and 32767

    any ideas?

    thanks alot
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Print settings - API?

    Oh, its because its not a range. Only a single page. There is another setting for that.

    wdPrintCurrentPage

    Then also try with double quotes around the page value.

    VB Code:
    1. Range:=wdPrintFromTo, From:="1", To:="3"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Re: Print settings - API?

    Robdog,

    get the range error again for:

    VB Code:
    1. wrd.ActiveDocument.PrintOut , , Range:=wdPrintFromTo, _
    2.     From:="1", To:="2"

    and for this wdPrintCurrentPage I get the same.

    Maybe I should have mentioned I am opening word from excel, would this make a difference?

    I recorded a macro in word to print the pages 1 & 2 and I get this:

    [Highlight=VB]Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
    wdPrintDocumentContent, Copies:=1, Pages:="1-2", PageType:= _
    wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=FalseVBCODE]

    could me alter this in anyway maybe?

    thanks
    The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Print settings - API?

    VB Code:
    1. wrd.ActiveDocument.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:=wdPrintDocumentContent, Copies:=1, Pages:="1-2", Background:=True, PrintToFile:=False
    For printing a range but I'm not sure about the parameter wdPrintAllPages for PageType
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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