I created an .hta application that generates XML from Excel Sheets and the reverse, the thing is that when I do the reverse, generate Excel Sheets from XML files, i need to print that sheet to pdf.
I try creating a macro that receives as a parameter the name of the final pdf file like this:
Sub print2pdf(filename)
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, PrToFileName:=filename
End Sub
and then i call the macro in the .hta application with this command:ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, PrToFileName:=filename
End Sub
ExcelAppA.run "print2pdf ""F:\ProjectoFCUL\OENG\PDFs\teste_disc_A.pdf"""
(i tried a lot of combinations with double quotes or single quotes, but i get no pdf file).
I tried create the macro with no parameters and with that i got a pdf file, the thing is that i need to generate a pdf based on the xml filename and in cycle, so i need to pass the filename as a parameter.
I also tried to invoke the printOut function from my .hta application, but it doesn't work. Is there any way to do it
Thanks,

print out to .pdf or calling a macro with parameter
Bjoern Graf
jlorga
Probably this is a solution
Function PrintToPDF(MyFile As String, MyDir As String)
ChDir MyDir
Dim Fs
Set Fs = CreateObject("Scripting.FileSystemObject")
ActiveWorkbook.PrintOut Copies:=1, _
ActivePrinter:="Acrobat PDFWriter op LPT1:", _
printtofile:=True, _
prtofilename:=MyFile
'There is also a file craeated (without extension) and a size of 0 Bytes
'I don't know where he comes from; I don't need that file, do drop it
Fs.DeleteFile MyDir & "\" & MyFile
End Function
Sub Test()
Dim Idx, Max, MyDir As String, MyFile As String
Max = 5 'Limit of the loop; ie rows count of filelist
Application.ScreenUpdating = False
For Idx = 1 To Max
MyDir = "E:\Temp\PDF" 'existing directory
'Substitute Mybook_ with the actual filename
'Myfile = name without extension!
MyFile = "Mybook_" & Idx
PrintToPDF MyFile, MyDir
Next
End Sub
Suc6
Kind regards
FiftyFive
JaredJ
I believe this happens because i have to deselect the option Not send fonts to pdf.
Mister2zx3
Hi,
I am facing same problem. PDF file created cannot be open. I de-checked "Do not send fond to 'Adobe PDF' " too.
Any solution to it
Red Jazz Of Progressive Blood
I solved the problem in two ways, the first only works if you do not have hyperlinks in your word document, because if you have them they will became inactive in the pdf file. You can call the pdf distiller and create a pdf file, here goes some example code:
Set fso = CreateObject("Scripting.FileSystemObject")
sTempFile = fso.GetSpecialFolder(TemporaryFolder) + "\" + fso.GetTempName()
WordApp.ActivePrinter = "Adobe PDF"
WordApp.ActiveDocument.PrintOut False , , , sTempFile
WordApp.ActiveDocument.SaveAs("filename.doc") WordApp.Documents.Close WdDoNotSaveChanges
WordApp.Application.Quit WdDoNotSaveChanges
oDistiller.FileToPDF sTempFile, fileName, "Print"
oDistiller.Application.quit
fso.DeleteFile( sTempFile )
To keep hyperlinks active in the pdf file (if they exist in the word document) if you have Acrobat Professional 6.0 or 7.0 installed, you can activate the Adobe menu in Microsoft Word and then you can invoke this line:
wordAppA10.ActiveDocument.SaveAs("filename.doc")
wordAppA10.ActiveDocument.CommandBars("PDFMaker 7.0").Controls(1).execute
wordAppA10.Documents.Close WdDoNotSaveChanges
Note that you have to disable the options prompt for pdf filename and view pdf results if you want no interaction with acrobat or word during the process.
rauhanlinnake
I've heard all kinds of bad things about using Adobe's PDF printer driver in this way. You might consider one of the many free third party PDF drivers. I use PrimoPDF, I have used CutePDF, and I've tested many others, including PDF995 and others I can't remember. All of them worked reasonably well, and you could work them into your code as easily. You don't get all the bells and whistles (and hassles) of Adobe, but generally people just want a hard copy they can read.
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______