Results 1 to 9 of 9
  1. #1
    5 Star Lounger Ruff_Hi's Avatar
    Join Date
    Feb 2001
    Location
    New York, New York, USA
    Posts
    768
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Test if Adobe Installed (Excel VBA XP)

    I'm looking for some code to test if abode pdf distiller is installed. We are writing an application that has 3 print options ...

    print to paper
    print preview
    print to pdf

    ... and I want to grey out the 'print to pdf' if distiller is not installed.

    In the past I have used code like

    <pre>Dim myPDF As pdfDistiller
    Set myPDF = New pdfDistiller
    myPDF.FileToPDF vFileName & ".ps", _
    vFileName & ".pdf", ""</pre>


    but this only works if I have checked the reference to the distiller. Obviously, on machines without distiller installed, this code will not even compile. Which brings me back to some code to test if distiller is installed - then I can give the user the 'print to pdf' option and execute the code above.
    (Location Australia, then UK, but now USA. Heart, outlook, attitude, etc always Australian)
    Quote: "All Happiness is the release of internal pressure"

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Test if Adobe Installed (Excel VBA XP)

    Hi Tim,

    I'm sure there's more than one way to do it, but here's one option:
    <pre>Sub UseDistiller()
    Dim oDistiller As Object
    Set oDistiller = GetPdfDistiller
    If oDistiller Is Nothing Then
    MsgBox "Sorry! Distiller isn't installed"
    End If

    ' Do stuff with distiller
    End Sub
    '
    Function GetPdfDistiller() As Object
    On Error Resume Next
    Dim oPDFDistiller As Object
    ' Not sure what the actual class name is for distiller:
    Set oPDFDistiller = CreateObject("Adobe.PDFDistiller")

    Select Case Err.Number
    Case 0
    Set GetPdfDistiller = oPDFDistiller
    Case 429
    Set GetPdfDistiller = Nothing
    Case Else
    ' Some other error occurred
    ' that you probably want to handle
    Set GetPdfDistiller = Nothing
    End Select
    End Function
    </pre>


    The error that's thrown when a COM object can't be created is 429. Hope this helps!

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

    Re: Test if Adobe Installed (Excel VBA XP)

    You could use late binding:

    Dim myPDF As Object

    On Error Resume Next

    Set myPDF = CreateObject("PDFDistiller.PDFDistiller.1")
    If myPDF Is Nothing Then
    MsgBox "PDF Distiller is not available.", vbExclamation
    Exit Sub
    End If

    On Error GoTo 0 ' or to an error handler label

  4. #4
    5 Star Lounger Ruff_Hi's Avatar
    Join Date
    Feb 2001
    Location
    New York, New York, USA
    Posts
    768
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Test if Adobe Installed (Excel VBA XP)

    Thanks Guys - that is exactly the code that I was looking for. I created a function to tell me if the PDF is installed and then went from there.
    (Location Australia, then UK, but now USA. Heart, outlook, attitude, etc always Australian)
    Quote: "All Happiness is the release of internal pressure"

  5. #5
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Test if Adobe Installed (Excel VBA XP)

    Tim

    I have just played with the two bits of code Andrew77's code says I don't have Adobe Distiller and Hans's says I do.

    I do have it installed so I suggest you get it checked <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Jerry

  6. #6
    5 Star Lounger Ruff_Hi's Avatar
    Join Date
    Feb 2001
    Location
    New York, New York, USA
    Posts
    768
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Test if Adobe Installed (Excel VBA XP)

    Thanks Jezza - I was using Hans code and had to fake it out (ie always set my IsDistillerInstalled to false) to see how my code handled that outcome.
    (Location Australia, then UK, but now USA. Heart, outlook, attitude, etc always Australian)
    Quote: "All Happiness is the release of internal pressure"

  7. #7
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Test if Adobe Installed (Excel VBA XP)

    As I mentioned in my original post, I didn't know the correct name for the Distiller object, because I don't have Distiller on my machine. Changing the name to the correct name, listed in Hans' post, should result in correct operation. The only difference in mine is that I split out the late-binding attempt into a separate function.

  8. #8
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Test if Adobe Installed (Excel VBA XP)

    Thanks Andrew

    I hope I didn't come across as criticising your work. if so I am sorry. It was just a friendly warning to Tim <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Jerry

  9. #9
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Test if Adobe Installed (Excel VBA XP)

    No problem. I should have been clearer in my original post.

    Cheers.

Posting Permissions

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