• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 878
  • Last Modified:

running AdobePDFMakerForOffice from VBA in Visio

With Acrobat XI installed, the following VBA code works correctly in Microsoft Word, and with very minor changes, also works in Excel. However, it does not work in Visio. In Visio, the code finds the COM AddIn successfully, but COM.Object is Nothing. Consequently, the assignment “Set pmkr = COM.Object” does not create an error, but pmrk is Nothing.
 
Any ideas why the code finds the COM addin but the object is null?
 
BTW, if you run the COM AddIn from the Acrobat tab on the Visio ribbon, it creates the PDF correctly.

Thanks...
Sub ConvertToPDF()
' ConvertToPDF - convert the current document to a PDF file
   
    Dim COM                     As COMAddIn
    Dim pmkr                    As AdobePDFMakerForOffice.PDFMaker
    Dim stng                    As AdobePDFMakerForOffice.ISettings
   
    Set pmkr = Nothing ' locate PDFMaker object
    For Each COM In Application.COMAddIns
        If InStr(UCase(COM.Description), "PDFMAKER") > 0 Then
            Set pmkr = COM.Object
            Exit For
        End If
    Next
   
    If pmkr Is Nothing Then
        MsgBox "Cannot Find PDFMaker add-in", vbOKOnly, ""
        Exit Sub
    End If
   
    MsgBox "Success"
    ' do useful stuff here
 
End Sub

Open in new window

0
Scott Helmers
Asked:
Scott Helmers
  • 11
  • 10
  • 7
  • +1
2 Solutions
 
FarWestCommented:
what version of Visio you have?

is there any problem of using visio export to PDF feature using Visio VBA like this
Public Sub PrintPDF()
ActiveDocument.ExportAsFixedFormat FixedFormat:=visFixedFormatPDF, OutputFileName:="C:\test.pdf", Intent:=visDocExIntentPrint, PrintRange:=visPrintAll
         
End Sub

Open in new window

0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
I'm using Visio 2010.

Good question about the built-in export to PDF. The reason I can't use that feature has to do with layers. The PDF format allows the user to turn visibility of Visio layers on and off as shown here for a simple flowchart saved to PDF:Visio layer control in PDF Unfortunately, Visio's built-in PDF export doesn't allow explicit control over layers and apparently "flattens" all layers. The Acrobat add-in, however, does allow layer control during the PDF creation process:Acrobat PDFMaker layer dialog Consequently, I need a way to retain the layers, and using VBA to automate the Acrobat PDFMaker seems like the logical method. The puzzle at the moment is why it works fine in Word but doesn't in Visio.
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Scott,

I've used COM calls only for Excel, PowerPoint, and Word, so can't help you with Visio. But I remember the first time I tried an Excel call (having started with Word) and found out that Excel didn't like ActiveDocument — it has to be ActiveWorkbook. I was then more careful when I did my first PowerPoint call and learned from the doc that it's ActivePresentation. So my only advice, which may or not be helpful, is to check the Visio-specific COM doc to see if something jumps out at you:
https://msdn.microsoft.com/en-us/library/office/ff766485.aspx

My experience is that the COM doc is excellent. Good luck with the code! Regards, Joe
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
FarWestCommented:
sure you have a very good reason not use built in export
but unfortunately XI does not support Visio
check this Adobe Help Page
https://helpx.adobe.com/acrobat/kb/pdfmaker-unavailable-office-2007-office.html
in which it is mentioned
"*Note:  Microsoft Publisher and Microsoft Visio are no longer supported in Acrobat XI"

supporting layer is not an easy job that can be handled with VBA

but I will search with you for a solution, and maybe third party tools is available around


have a good luck
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
Oops...I just noticed that you said you're using Visio 2010. That previous link I sent is for Visio 2013. Here's the 2010 one:
https://msdn.microsoft.com/en-us/library/office/ff766485%28v=office.14%29.aspx

Regards, Joe
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Thanks, Joe. Visio does use ActiveDocument, so the code works up to the moment of trying to get the reference to COM.Object. The problem appears to be that COM.Object is not assigned.

Thanks, FarWest. I see the reference to Visio no longer being supported but I think that information has been superseded -- or at least it appears that way. At the top of the page you cited is a link to  a page containing supported web browsers and applications. On that page is a section for Visio and it looks to me like Visio as part of 32-bit Office 2010 is supported by XI Pro. Do you read that chart the same way?Visio PDF compatibility Also, as I mentioned above, if you run the COM AddIn from the Acrobat tab on the Visio ribbon, it creates the PDF correctly.
0
 
FarWestCommented:
No, but Visio and Publisher are specifically excluded among other office suite applications,
as I understand Supporting office with XI does not cover publisher and Visio, neither 64 or 32 bit,
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
> The problem appears to be that COM.Object is not assigned.

Maybe it hasn't been registered yet in the ROT when that code runs. Try taking focus away from Visio, which is when it gets regsitered in the ROT. A simple Minimize/Restore will work for testing, although you may not want your user to see the screen disappear/re-appear like that, in which case the permanent solution will involve a less intruisive way to take focus away from Visio, such as a DLL call to GetDesktopWindow — but first let's see if that solves the problem, which Minimize/Restore will tell you. Regards, Joe
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Joe -- I minimized/maximized the Visio window before running the macro, but there is no change. The COM Addin is still found but the object is Nothing. Good suggestions -- keep them coming.
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
Scott,
I'm trying to help based on just theory, because I don't have Visio 2010 (or any release of it), but at this point I'm out of ideas. I looked in SharePoint Designer 2010 (where I found Picture Manager), but, unfortunately, Visio isn't in there. I'll give it some further thought, but I'm not hopeful of finding anything without a testing platform. Regards, Joe
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
No problem, Joe, thanks for trying.

One thought: in my sample code, COM does return a GUID. Is there a way to set an object reference based on a GUID? Something like
   Set pmkr = Application.COMAddIns.GetObjectFromGUID(COM.GUID)
similar to adding a reference from a GUID?
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
Scott,

Sorry for the delay in responding — took my critters to the vet. I've never made any COM calls with GUID as a parameter, so I can't help you there. A web search for "guid com object" gets some interesting hits (including How to find the Object that belongs to a GUID), but I haven't tried any of it.

One other thought. You said that you minimized/maximized the Visio window before running the macro — try doing it inside the macro. That's what fixed the most recent problem I had with a COM call to an Excel object (although it was in a different scripting language, not VBA). Regards, Joe
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Thanks, Joe. I'm working on a couple of other angles and will post here if I find anything that works.
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
Thanks, Scott. This is a fascinating one and I'm very interested in learning what works. Regards, Joe
0
 
FarWestCommented:
@scott you are now challenging Adobe,  I wish good luck to you, and hear from you the happy news soon,
although I have a plan B for you :)
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Joe -- I agree that it is, um, something -- not sure I'd go with fascinating ;-). I do find it bizarre, however, that the code works perfectly in Word but in Visio it finds the COM addin and returns every one of its properties except the object itself. (BTW, I didn't try minimizing and maximizing within the VBA code with no change in behavior.)

FarWest -- I'm working on plan C or D by now but would love to hear your idea!
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
> I didn't try minimizing and maximizing within the VBA code

I presume that's a typo and you meant did — right?
0
 
FarWestCommented:
My plan B is: I will develop a tool that will generate multi-layered PDF from Visio without the need of XI at all, (ver 0.01 release can be within a week or so)
we can work together on it, short term you will use it to solve your problem, long term we can partner together to enhance it and sell it, Joe also  can participate if he wants to

what do you think? can we name it Plan M for Money
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Right, Joe -- did try.

FarWest -- I like the idea. I will need to sell my client on the concept of using brand new code in their production environment. My guess is they will like the idea but will defer using it until it's been tested and packaged into a product-like offering. But there seems to be a definite need for an easy way to publish Visio diagrams to PDF with layer control, something that can be driven from a button on the ribbon with an option to flatten or retain layers, and that can also be driven from code without the need for user interaction. I'm definitely willing to work with you.
0
 
FarWestCommented:
good,
sure, it should be with minimal user interaction,
the concept in mind  will also allow the user to select if he would like to combine more than one layer as single layer while keeping the other layers so for building diagram you can flatten all but network layer and so.
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Sounds great. But keep in mind the second half of what I need -- it should also be possible for VBA (or other) code to set layer options and create the PDF without any user interaction.
0
 
FarWestCommented:
I think earlier releases can support command line options, and can be called from scripting by shell objects
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
> Joe also can participate if he wants to

I would normally jump at the opportunity to monetize the gargantuan amount of time I spend gratis at EE, but you guys are way over my head on Visio, a product that I never use (I entered the thread because of my experience in writing code that makes COM calls for Excel, PowerPoint, and Word). That said, I'm working on a Shopify website to sell software that I've developed, and if you folks come up with a commercially viable product, perhaps we can partner in some way that makes sense for all of us. In any case, thanks for the offer — much appreciated! Regards, Joe
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Thanks for jumping in, Joe. And your potential Shopify site could be very interesting. I'm not currently using a site to sell utilities and such, so working with someone who's already walking down that path makes sense.

BTW, in one of your posts you said that the COM doc is excellent. Where is the best place to get started learning more about COM?

FarWest -- a command line option is workable but I was thinking more of the object-style approach that would allow setting properties and then invoking a "CreatePDF" method to generate the document. However, I'm flexible...
0
 
Martin LissOlder than dirtCommented:
@scott: This question has been designated as Neglected, and so as a Cleanup Volunteer for this TA the question showed up in my list to close. Normally closing questions and assigning points (if any) is fairly straightforward, but I couldn't decide how to do that in this case and the best solution would be if you were to close it. Thanks in advance for doing that.
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
> Where is the best place to get started learning more about COM?

Hi Scott,

Sorry I missed that question when you asked it a month ago. I've had some cases of not receiving notification emails from EE, and that was probably one of them.

I think the Microsoft COM site is a good place to start:
https://www.microsoft.com/com/default.mspx

The Word and Excel sections are very good:
https://msdn.microsoft.com/en-us/library/kw65a0we.aspx
https://msdn.microsoft.com/en-us/library/wss56bz7.aspx

Of course, for your purposes, take a look at the Visio section:
https://msdn.microsoft.com/en-us/library/office/ff765377.aspx

Regards, Joe
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Sorry for letting this slide off my radar... I will close it now.
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
I never really closed the chapter on this question because my client accepted a slight change of direction and eliminated the need for dealing with layers in the PDF. Consequently, my task became quite simple in that my code could now use the built-in export to PDF capability in Visio.
0
 
Martin LissOlder than dirtCommented:
Thanks.
0
 
Joe Winograd, Fellow&MVEDeveloperCommented:
Scott,
Thanks for letting us know how it eventually played out and what worked — and thanks, too, for the points. Regards, Joe
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 11
  • 10
  • 7
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now