Consulting

Results 1 to 7 of 7

Thread: Convert Word to PDF

  1. #1
    VBAX Regular
    Joined
    May 2010
    Posts
    10
    Location

    Convert Word to PDF

    Hi,

    I have been cracking my head all afternoon on how to convert a word file into PDF. After many hours of serarching I got the piece of code below thanks to this site. I twicked it to suite my needs by changing the the file name & path. To cut the long story short, it saves a ".ps" file and then converts it to ".pdf" file.

    The above only works if I step through the script with F8. When executed with Run or with a button it gives "The file is used being by another process" error message.

    Can anybody advise me on how to resolve the above issue?


    [vba]
    Dim PSFileName As String
    Dim PDFFileName As String
    PSFileName = SavedDir & "\" & StrTrimmed & "_" & Format(Date, "ddmmyyyy") & "_" & Format(Time, "mmhhss") & ".ps"
    PDFFileName = SavedDir & "\" & StrTrimmed & "_" & Format(Date, "ddmmyyyy") & "_" & Format(Time, "mmhhss") & ".pdf"

    ' Print the file to the postscript file
    Dim MyDoc As Document
    Set MySheet = ActiveDocument

    ' Print out to post script file
    MyDoc.PrintOut outputfilename:=PSFileName, copies:=1, ActivePrintermacgx:="Acrobat Distiller", _
    printtofile:=True, collate:=True

    ' Convert the postscript file to .pdf
    Dim myPDF As PdfDistiller
    Set myPDF = New PdfDistiller
    myPDF.FileToPDF PSFileName, PDFFileName, ""
    [/vba]

    Kind Regards,
    ChrisMac

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    992
    Location
    Can you trap that error?

    Even if you can't, it seems to be a timing issue which also appears to be a common problem.

    Check out this thread and adapt the Pause sub in message #5.

    Good luck!

    David


  3. #3
    VBAX Regular
    Joined
    Jun 2010
    Posts
    22
    Location
    hi dear ,

    tell me your email and I will send you a convertor program with explain how you can use it

  4. #4
    VBAX Regular
    Joined
    May 2010
    Posts
    10
    Location
    Quote Originally Posted by freehope
    hi dear ,

    tell me your email and I will send you a convertor program with explain how you can use it
    Hi, Send to chrizke@yahoo.com

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    If you must do it programmatically, then the timing issue is the problem. Follow Tinbendr's suggestion. You need to add a Pause.

  6. #6
    Hi, ChrisMac.
    As for me, I have seldom tried to convert a word file into PDF. I wonder have you ever worked it out? Do I need another 3rd party manual toolkit? When it comes to PDF converting process, I have another question, I wonder have you ever tried to convert pdf to other image files before? As for myself, I am testing the related PDF to PNG converting,
    PDF to BMP converting , and PDF to JPG converting programs these days. Do you have experience about it? Any suggestion will be appreciated. Thanks in advance.



    Best regards,
    Lee

  7. #7
    VBAX Regular
    Joined
    Jan 2016
    Posts
    12
    Location
    pdf-->jpeg ....In my case, such conversion results in a dramatic loss of image quality

Posting Permissions

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