PDA

View Full Version : Convert Word to PDF



ChrisMac
07-03-2010, 09:34 AM
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?



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, ""


Kind Regards,
ChrisMac

Tinbendr
07-03-2010, 06:59 PM
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 (http://www.vbaexpress.com/forum/showthread.php?t=25184).

Good luck!

freehope
07-04-2010, 11:49 AM
hi dear ,

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

ChrisMac
07-04-2010, 02:13 PM
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

fumei
08-31-2010, 10:38 AM
If you must do it programmatically, then the timing issue is the problem. Follow Tinbendr's suggestion. You need to add a Pause.

arronlee
12-29-2015, 03:16 AM
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 (http://www.pqscan.com/convert-pdf/to-bmp-csharp.html) , and PDF to JPG converting programs (http://www.pqscan.com/convert-pdf/to-jpg.html) these days. Do you have experience about it? Any suggestion will be appreciated. Thanks in advance.



Best regards,
Lee

markecb
01-15-2016, 02:17 PM
pdf-->jpeg ....In my case, such conversion results in a dramatic loss of image quality