Results 1 to 8 of 8
  1. #1
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72

    VBA to convert DWG files to PDF

    Hello everyone... I'm trying to convert AutoCad DWGs to PDFs using VBA (in Access). I have a reference set up to the Adobe Acrobat 10.0 Type Library but I'm trying to get the correct syntax to do a CreatePDF on all DWGs in a folder. This would include subfolders and this does work when going through the Adobe UI. Does anyone know the code for this, or would it take a loop with as many iterations as there are DWGs? I've looked through all the documentation I can find and I can't seem to get a handle on this. Thanks in advance... Glenn

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    IF Autocad allows vb, then you must print thru Autocad to the PDF printer.

  3. #3
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    Actually, I was thinking of doing this without going through AutoCad. It can be done in Adobe's user interface without having Autocad installed on the machine. Adobe has Autocad filters included to work around that. So I figured it must be possible to automate with VBA. I just can't find the VBA syntax for Adobe's object model.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Hello Glenn,

    I believe what you will want is OLE Automation via the AcroExch class. I have not tried to manage DWG files within Acrobat. I know Illustrator can handle these...

    If I were trying to get the job done, I would start with the reference guide linked to in this post.
    https://www.accessforums.net/code-re...tml#post222559

    There may be an updated version of the reference but that is where I would start. Also, yes, you will want to iterate your DWG files within a given directory.

  5. #5
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    Thanks, ItsMe... It looks like that will do the trick. I ran the code you referred to me on one dwg and it worked saving one dwg as a pdf file. However, do you know how I might adjust the parameters so that it saves all pages that were in the original document? I took off all the parameters and no pages were saved with the pdf. So I got an error when I tried to open it with Adobe. Thanks, Glenn... How's everything on the west coast?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Things are going strong out here, Glenn. I have some things to take care of, at the moment. A little later I will review your post and see what I can come up with.

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    OK, that was not simple. Well, actually, it is simple. I just don't know where to find good documentation. Anyway, you may need more functionality than just creating the PDF. The following is not going to let you add comments, play around with layers, etc. There are other references that can be made to take advantages of additional libraries. I had to add PDFMaker API 1.0 Type Library

    Also, I stumbled across something about acrobat no longer supporting 3D edits directly and you need a third party add in. Anyway, this worked for me. I used Illustrator to create a simple DWG and all the layers were in the PDF when all was said and done.

    Code:
    'Reference PDFMaker API 1.0 Type Library
    Dim strGetFile As String
    Dim strMakeFile As String
    
    strGetFile = "\\ServerName\Folder\Sample.dwg"
    strMakeFile = \\ServerName\Folder\Result.pdf
    
    Dim objPDFMaker As New PDFMAKERAPILib.PDFMakerApp
    Dim lngResult As Long
    
    lngResult = objPDFMaker.CreatePDF(strGetFile, strMakeFile)
    
    'Returns 0 if good
    'Returns -1 if bad

  8. #8
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    Now THAT looks like it definitely worked. No AutoCad on this machine and yet it appears to have completely converted the DWG to PDF. And by the way, the intent WAS to convert the file as is... no need for added comments, layer manipulation, etc. We just need a job that will make PDF copies of all DWG files that reside in a folder or any of its subfolders. And I have code that will iterate through all subfolders of a main folder. Then keeping the file name and only changing to the .PDF is all that is left to do.
    Thanks again and... left's hear it for the west coast one more time... hip hip... hooray... hip hip...

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

Similar Threads

  1. using mdb files which are backed up hourly into zip files
    By Robbie MacKinnon in forum Access
    Replies: 3
    Last Post: 05-05-2015, 05:02 AM
  2. Replies: 4
    Last Post: 05-15-2014, 12:49 PM
  3. How to convert from .accdb to executablle files
    By cheesewizz in forum Access
    Replies: 1
    Last Post: 08-29-2012, 06:48 PM
  4. Can you convert .mdb to .wdb??
    By DeeMax45 in forum Access
    Replies: 2
    Last Post: 01-22-2012, 06:11 PM
  5. Replies: 1
    Last Post: 02-21-2011, 09:55 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