Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Convert Word>PDF other apps default prnter changin

    W97 - VBA

    I have code which converts Word files to PDF.
    the problem or result thats happening is:
    when I print to the PDF printer driver & reset the default printer in Word.
    It changes the other applications printer.

    We have standard naming conventions for our printers
    ie floor & direction/location in building
    eg L9_SW_DOC_PQ

    after the code is run - the default printer is set in Word.
    However in Lotus Notes the default printer name is some obsecure name.
    eg SW_DOC_PQ on al.

    I have the following code:

    'obtain users word default printer
    'reason is to reset printer after writing to PDF printer.
    SetLocalPrinter = Application.ActivePrinter

    'set printer to PDF printer
    Application.ActivePrinter = strPDFPrinter

  2. #2
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Edited later...
    Whoops - just noticed you had stated W97 - hopefully it may still help.
    ****************

    <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q209/7/22.ASP>Q209722</A> :
    WD2000: Setting ActivePrinter Changes System Default Printer
    ------------------------------------------------------------
    The information in this article applies to:
    Microsoft Word 2000
    ------------------------------------------------------------
    SYMPTOMS
    When you specify the active printer using the Visual Basic for Applications ActivePrinter property, the command resets the system-level default printer.
    NOTE: This behavior does not occur when you change printers using the Print command on the File menu.

    ***

    I suffer(ed) from this problem with a macro that sent a doc to my fax driver - the result being that in Excel the default printer was set as [ blank ] - i.e. none - after running the macro, even though it reset in Word OK.

    This is what I have:
    Dim sCurPrinter As String
    With Application
    sCurPrinter = .ActivePrinter ' Store current printer.
    .ActivePrinter = "RelayFax Printer Driver on NE00:" ' Change Printers.
    ActiveDocument.PrintOut ' Print the active document.
    .ActivePrinter = sCurPrinter ' Set printer back to current.
    End With

    I also have a suspicion that I needed to resolve a more explicit name for the Fax printer. If I simply recorded a macro to get the code for redirecting to the Fax, I got this:
    ActivePrinter = "RelayFax Printer Driver"
    However, adding a watch on 'ActivePrinter' actually displayed it as:
    "RelayFax Printer Driver on NE00:"
    Changing the ActivePrinter to the line above did seem to help reset the printer for Excel.

    Hope this makes some sense...

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Convert Word>PDF other apps default prnter changin

    I think Leif has found the bug report which applies. I would also suggest that it appears to apply in Word97 as well.

    The work around would be to execute the dialog instead
    <pre>With Dialogs(wdDialogFilePrintSetup)
    .printer = "DRAGONp003046"
    .DoNotSetAsSysDefault = True
    .Execute
    End With</pre>

    Execute means it happens without you seeing the dialog. Reverse the statements to populate a variable which resets the original printer when done.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Leif

    Thanks for pointing me in the right direction about the MS bug.
    The fix Microsoft have provided I already had in my code.
    ie
    store current printer in variable
    change printer
    print or create PDF document file
    reset printer to default current printer

    I applied your suggestion ie setting printer name to be more specific ie
    strPDFPrinter = "5D PDF Creator on Ne06"

    yet I didnt have much success.
    When you mentioned you added a watch on the 'ActivePrinter'
    what do you actually mean by this?

    I also applied Andrews suggestion again without much success.
    Thanks Diana

  5. #5
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    In the VB window:
    Debug | Add Watch (if you have the cursor in 'ActivePrinter' it will automatically offer that as the expression to watch)
    You need the 'Watches' window open - as you step through the code (F8) you can 'watch' what the code is doing.

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Thanks Leif

    I managed to get the system default printer right.
    ie when changing Words default printer, the lotus notes printer is set correctly.
    My orginial code already had microsofts suggestion
    ie
    store current default printer
    change printer to PDF printer driver
    print active document (converts to PDF file)
    set back to default printer.

    we have an ini file that stores the default printer name for the users.
    I was accessing this file to obtain info.
    When I amended code to access printer from application made other amendments it was fine.

    my code follows:

    'obtain users word default printer from file LocalConfig.ini
    'reason is to reset printer after writing to PDF printer.
    strLocalPrinterDOC = GetPrivateProfileString("DefaultPrinters", "DefaultPrinter_DOC")
    strLocalPrinterA4 = GetPrivateProfileString("DefaultPrinters", "DefaultPrinter_A4L")

    'obtain default printer from word application
    SetLocalPrinter = Application.ActivePrinter
    strLocalPrinter = SetLocalPrinter

    'if the A4 printer or Doc printer is current active printer - set
    If (InStr(strLocalPrinter, strLocalPrinterDOC) > 0) Or (InStr(strLocalPrinter, strLocalPrinterA4) > 0) Then
    SetLocalPrinter = Application.ActivePrinter
    End If


    'determine is user is logged onto network or via Citrix server
    'if on Citrix PDF file will need to be generated using different methods.
    'if on citrix server - set printer as current printer
    If Len(Dir(CitrixFileName)) > 0 Then
    blnLoggedOntoCitrixServer = True
    PDFPrinter = SetLocalPrinter

    Else
    'else if on network - set printer to PDF printer driver
    blnLoggedOntoCitrixServer = False
    PDFPrinter = "5D PDF Creator"
    End If

    'create a new file by performing a save as for current active document has formatting changes
    ActiveDocument.SaveAs sNewFileName

    'set printer to PDF printer
    Application.ActivePrinter = PDFPrinter

    'if user is logged onto citrix server - print file to current printer with option 'print to file'
    'as using Adobe Distiller to generate PDF file, Distillers procedures is file needs to be
    'converted to postscript 1st then convert to PDF.
    If blnLoggedOntoCitrixServer = True Then
    ActiveDocument.PrintOut Copies:=iNumCopies, Range:=cRange, OutputFileName:=strPostScriptFile, Pages:=cPages, PrintToFile:=True

    Else
    'else if logged onto network - print file to PDF printer driver
    'note:PDF printer driver converts directly as PDF file
    ActiveDocument.PrintOut Copies:=iNumCopies, Range:=cRange, Pages:=cPages
    End If


    'call functions to reset users word environment

    'after writing to PDF printer reset printer back to default printer
    Application.ActivePrinter = SetLocalPrinter

    'close doc
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

    'perform housekeeping & delete word document
    Kill strDOCFile


    Thanks for your help -Diana
    Please note that I format my code so its easy to read, however each time I post code the format doesnt appear, I manually format ie space bar etc -but doesnt reflect my formatting - does anyone know why?

  7. #7
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Hi Diana,

    I don't why leading spaces do not carry forward into messages, but if you use [tab ], (without the space) it will insert some space.You can string them together for extra space as required. Check the tag panel. Also put [pre ] just before the start of your code and [/pre ] at the finish. This uses a monospaced font (prestige presumably) which is best for code. Again, leave out the space just before the closing ].

    Hope that is of help

    Andrew C

  8. #8
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Diana,

    If you use the [ pre ] tags as Andrew has suggested, you do get all your code formatted

    eg- without tags:
    if strString = "A" then
    strString = " AAA " & "BB"
    end if

    and the same code with tags:
    <pre>if strString = "A" then
    strString = " AAA " & "BB"
    end if
    </pre>


    However, this has two disadvantages:
    1. If the code has long lines of text, it makes a very wide window, which means anybody reading it may have to scroll right. The code you've posted has a few long lines like that. If you're viewing in flat mode, it affects every post.
    2. If the code is copied and then pasted directly into VBA, carriage returns are not copied (try pasting in that piece of code from above into VBA). You can get around that. In word, paste it into the document, replace all "^l" by ^p, then copy it again and paste it into VB. Or copy it into Excel, then copy it from Excel and then paste it into VB.

    I'd suggest saving the code as a .txt file, then attaching that code to your post. That gets across all of the above problems.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  9. #9
    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: Convert Word>PDF other apps default prnter changin

    One other trick: you can use the [small ] [/small ] tags inside the [pre ] [/pre ] tags to shrink the text down a size.

  10. #10
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Geoff

    In your step 2 you don't need to replace the ^l's with ^p's. Just pasting as is into Word and then copying again will bring it to the VBE the correct way. That is one of GaryF's tricks.

    The other disadvantage is sometimes characters get interpreted in some way and get deleted from the code (I think '&' is an example)
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  11. #11
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Andrew,

    <hr>Just pasting as is into Word and then copying again will bring it to the VBE the correct way<hr>

    Thanks, I never realised that. That will save me some bother.

    <hr>sometimes characters get interpreted in some way and get deleted from the code<hr>

    Interesting.

    Would this line:
    ~ ! @ # $ % ^ & * ( ) _ + ` - = { } | [ ] : " ; ' < > ? , . /

    be the same if copied then pasted as this line?
    <pre>~ ! @ # $ % ^ & * ( ) _ + ` - = { } | [ ] : " ; ' < > ? , . /
    </pre>



    *** edited ***
    No, I haven't lost any of the characters
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  12. #12
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    PA
    Posts
    246
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Diana,

    I'm curious. I've seen a number of questions from coders regarding DOC->PDFvia VBA.

    My question is why go to the trouble as Adobe supplies a much more able macro with Acrobat that does what you are doing in addition to providing the ability to create richer PDF from your DOC's formatting (navigation, bookmarks, footnotes, etc.)? Is the supplied macro inadequate? Too complicated? Not working?

    If you don't like the choices that Adobe gives you for Word in their Distiller enabled macro, they give a very basic one for excel that can be adapted.

    Seriously, I am asking because the Adobe PDFMaker macro works well for me, and yet I see people trying to duplicate it rather than use it, and I am operating with the presumption that anyone smart enough to write the code has got to know that PDFMaker is already there.

    What am I missing?

  13. #13
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    I'm curious too.
    I recall a thread where someone was trying to create a pdf using a macro that required no human intervention - I'm afraid I can't remember whether or not it was resolved.
    I would be interested in a macro that that took the document name, e.g. 'conversion.doc', and created a pdf called 'conversion.pdf' - I believe the Acrobat macro stops to ask for the file name.

    If this has been solved - please post!

  14. #14
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    PA
    Posts
    246
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    <hr>I would be interested in a macro that that took the document name, e.g. 'conversion.doc', and created a pdf called 'conversion.pdf' - I believe the Acrobat macro stops to ask for the file name.<hr>
    Adobe defaults: Distiller prompts for file name; PDFwriter does not.

    The <A target="_blank" HREF=http://www.adobeforums.com>Adobe User to User Forum</A> is similar to this lounge. The method of changing Distiller's default behavior is outlined there. If you can't find it by searching, just ask. There are a lot of knowlegable, helpful people there. I wish I could answer you directly, but I usually like to be prompted, so I never changed the distiller setting.

  15. #15
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    PA
    Posts
    246
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert Word>PDF other apps default prnter changin

    Just to clear up my last post. Leif, my suggestion for solving your issue is addressed on the Acrobat side, not by VBA. Acrobat's default automation is provided by JavaScript. (Though searching the <A target="_blank" HREF=http://www.adobe.com>Adobe site</A> for "IAC" will give you a lot of information on integration with VB/VBA. Also a lot in the forms SDK.) My gut feeling is that you can't write JavaScript to make this change "on the fly" for security reasons, so once you make the change for use with Word, it becomes Distiller's default behavior for all applications until you change it back.

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
  •