Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Save PDF
This Microsoft Save as PDF Add-in for 2007 Microsoft Office programs supplements and is subject to the license terms for the 2007 Microsoft Office system software. You may not use this supplement if you do not have a license for the software.
System Requirements
Supported Operating Systems: Windows Server 2003; Windows Vista; Windows XP Service Pack 2
This download works with the following Office programs:
Microsoft Office Access 2007 Microsoft Office Excel 2007 Microsoft Office InfoPath 2007 Microsoft Office OneNote 2007 Microsoft Office PowerPoint 2007 Microsoft Office Publisher 2007 Microsoft Office Visio 2007 Microsoft Office Word 2007
;Winbatch 2007C - Excel 2007 Workbook/Worksheet or Range to PDF ; ;requires Office 2007 and [free] PDF add-on (SaveASPDF) installed ; ;Stan Littlefield, July 20, 2007 ;//////////////////////////////////////////////////////////////////////// ;This is a just a quick script, as I just got 2007 installed. ;Lot to learn but this version of Excel looks promising and is ;totally different as a UI. ;//////////////////////////////////////////////////////////////////////// GoSub udfs IntControl(73,1,0,0,0) cXLS= DirScript():"test2007.xlsx" ;note newer file extension If ! FileExist(cXLS) Then Exit cPDF=DirScript():"test2007.pdf" oXL=CreateObject("Excel.Application") oXL.Visible = 1 oXL.ScreenUpdating = 1 oXL.UserControl = 1 oXL.DisplayAlerts = 0 If oXL.Version <12 Display(2,"Cannot Continue","This Script for Excel 2007") Goto End EndIf cResult=cPDF:" created" BoxOpen(cXLS:" opened..","Creating PDF From Range") n=0 xlTypePDF = 0 xlQualityStandard = 0 If FileExist(cPDF) Then FileDelete(cPDF) oXL.Workbooks.open(cXLS) oXL.ActiveWorkBook.Worksheets(1).Activate ;surprising XL4 macros still work in 2007 ;so if you needed to output only certain pages this ;would come in handy PgCnt = Int(oXL.ExecuteExcel4Macro("Get.Document(50)")) Message("Pages on Worksheet[1]",PgCnt) ;////////////////////////////////////////// ;I set up a UDF to take accept more than ;one type of PDF Output, so uncomment ;what you want to check out. ;NOTE: there are issues with the PDF only ;printing as landscape, and if I get a ;fix, I'll post it. ;////////////////////////////////////////// ;workbook as PDF pdf(1,oXL.ActiveWorkbook) ;worksheet as PDF ;pdf(2,1) ;Range as PDF ;pdf(3,"Inv") ;Pages on Sheet as PDF ;pdf(4,"1,1,1") ;I'm not sure this is needed, but it doesn't seem to hurt ;the PDF output should be created within 30 seconds While ! FileExist(cPDF) TimeDelay(1) n=n+1 If n>30 Then Break EndWhile If ! FileExist(cPDF) Then cResult=cPDF:" not created" BoxText(cResult) TimeDelay(1) BoxShut() :End oXL.Quit() oXL=0 Exit :WBERRORHANDLER oXL=0 ErrorProcessing(1,1,0,0) Exit ;//////////////////////////////////////////////////////////////////////// :udfs ;this just illustrates several choices for output ;you can midify to suit a range like "A1:D10" or a page sequence #DefineSubRoutine pdf(nChoice,var) IntControl(73,1,0,0,0) Select nChoice Case 1 oXL.ActiveWorkbook.ExportAsFixedFormat(::Type=xlTypePDF,Filename="%cPDF%",Quality=xlQualityStandard,IncludeDocProperties=@TRUE,OpenAfterPublish=@FALSE) Break Case 2 oXL.WorkSheets(%var%).ExportAsFixedFormat(::Type=xlTypePDF,Filename="%cPDF%",Quality=xlQualityStandard,IncludeDocProperties=@TRUE,OpenAfterPublish=@FALSE) Break Case 3 oXL.Range("%var%").ExportAsFixedFormat(::Type=xlTypePDF,Filename="%cPDF%",Quality=xlQualityStandard,IncludeDocProperties=@TRUE,IgnorePrintAreas=@TRUE,OpenAfterPublish=@FALSE) Break Case 4 sheet = ItemExtract(1,var,",") nFrom = ItemExtract(2,var,",") nTo = ItemExtract(3,var,",") oXL.WorkSheets(%sheet%).ExportAsFixedFormat(::Type=xlTypePDF,Filename="%cPDF%",Quality=xlQualityStandard,IncludeDocProperties=@TRUE,From=%nFrom%,To=%nTo%,OpenAfterPublish=@FALSE) EndSelect Return(1) :WBERRORHANDLER oXL=0 ErrorProcessing(1,1,0,0) Exit #EndSubRoutine #DefineSubRoutine ErrorProcessing(deleteIni,showerr,logfile,Err_Array) If VarType(Err_Array) ==256 WbError = Err_Array[0] wberrorhandlerline = Err_Array[1] wberrorhandleroffset = Err_Array[2] wberrorhandlerassignment = Err_Array[3] wberrorhandlerfile = Err_Array[4] wberrortextstring = Err_Array[5] wberroradditionalinfo = Err_Array[6] wberrorinsegment = Err_Array[7] Else WbError = LastError() End If WbTextcode = WbError If WbError==1668||WbError==2669||WbError==3670 ; 1668 ; "Minor user-defined error" ; 2669 ; "Moderate user-defined error" ; 3670 ; "Severe user-defined error" WbError = ItemExtract(1, IntControl(34, -1, 0, 0, 0), ":") WbTextcode = -1 End If WbErrorString = IntControl(34, WbTextcode, 0, 0, 0) WbErrorDateTime = TimeYmdHms() WbErrorFile = StrCat(DirWindows(0), "WWWBATCH.INI") If deleteIni FileDelete (WbErrorFile) IniWritePvt(WbErrorDateTime,"CurrentScript",WbErrorHandlerFile ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ErrorValue" ,WbError ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ErrorString" ,WbErrorString ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ScriptLine" ,WbErrorHandlerLine ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ScriptOffset" ,WbErrorHandlerOffset ,WbErrorFile) IniWritePvt(WbErrorDateTime,"VarAssignment",WbErrorHandlerAssignment,WbErrorFile) IniWritePvt(WbErrorDateTime,"VarInSegment" ,WbErrorInSegment,WbErrorFile) IniWritePvt("","","",WbErrorFile) End If WbErrorMsgText = StrCat(WbErrorDateTime,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"Current Script: ",WbErrorHandlerFile,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"Error# [",WbError,"]",@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"Error Text: ",wberrortextstring,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"[Extended Information] ",wberroradditionalinfo,@CRLF,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"On Line:",@CRLF,WbErrorHandlerLine,@CRLF) ;WbErrorMsgText = StrCat(WbErrorMsgText,"Offset: ",WbErrorHandlerOffset,@CRLF) If (WbErrorHandlerAssignment>"") Then %WbErrorHandlerAssignment% = "UNKNOWN" WbErrorMsgText = StrCat(WbErrorMsgText,"Assignment/Variable: ",WbErrorHandlerAssignment,@CRLF) If (WbErrorInSegment>"") Then WbErrorMsgText = StrCat(WbErrorMsgText,"In UDF/UDS: ",WbErrorInSegment,@CRLF) If logfile cSep = StrCat(StrFill("=",50),@CRLF) cLogFile = StrCat(DirScript(), "log.err") If ! FileExist(cLogFile) Then FilePut(cLogFile,StrCat("Error Log",@CRLF,cSep)) FilePut(cLogFile,StrCat(FileGet(cLogFile),WbErrorMsgText,cSep)) Display(2,"An Error Occured",StrCat("written to ",cLogFile)) Else If showerr WbErrorMsgText = StrCat(WbErrorMsgText,"[THIS ERROR NOT WRITTEN TO LOG FILE]",@CRLF) Message("An Error Was Encountered",WbErrorMsgText) End If End If Return(1) #EndSubRoutine Return ;////////////////////////////////////////////////////////////////////////
Article ID: W17455
File Created: 2008:04:10:15:10:48
Last Updated: 2008:04:10:15:10:48