Function RDB_Create_PDF(Myvar As Object, FixedFilePathName As String, _ OverwriteIfFileExist As Boolean, OpenPDFAfterPublish As Boolean) As String Dim FileFormatstr As String Dim Fname As Variant 'Test to see if the Microsoft Create/Send add-in is installed. If Dir(Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" _ & Format(Val(Application.Version), "00") & "\EXP_PDF.DLL") <> "" Then If FixedFilePathName = "" Then 'Open the GetSaveAsFilename dialog to enter a file name for the PDF file. FileFormatstr = "PDF Files (*.pdf), *.pdf" Fname = Application.GetSaveAsFilename("", filefilter:=FileFormatstr, _ Title:="Create PDF") 'If you cancel this dialog, exit the function. If Fname = False Then Exit Function Else Fname = FixedFilePathName End If 'If OverwriteIfFileExist = False then test to see if the PDF 'already exists in the folder and exit the function if it does. If OverwriteIfFileExist = False Then If Dir(Fname) <> "" Then Exit Function End If 'Now export the PDF file. On Error Resume Next Myvar.ExportAsFixedFormat _ Type:=xlTypePDF, _ FileName:=Fname, _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False On Error GoTo 0 'If the export is successful, return the file name. If Dir(Fname) <> "" Then RDB_Create_PDF = Fname End If End Function Function DigIn(sPath As String) Dim FS, f, f1, fc, s Set FS = CreateObject("Scripting.FileSystemObject") Set f = FS.GetFolder(sPath) Set fc = f.Files For Each f1 In fc ExtName = GetExtName(f1.Path) If ExtName = "xlsx" Then RDB_Workbook_To_PDF (f1.Path) End If Next For Each subfolder In f.SubFolders s = s & subfolder.Path DigIn (subfolder.Path) Next End Function Function GetExtName(ScanString As String) As String '******************************************************* '<DESC> Retrieves File Extension Name from full ' directory path</DESC> '<RETURN> File Extension Only ' </RETURN> '<ACCESS> Public '<ARGS> FullPath: ' Full Filepath incl. Filename ' </ARGS> '<USAGE> If GetExtName("c:\autoexec.bat") ' </USAGE> '******************************************************* Dim intPos As String Dim intPosSave As String If InStr(ScanString, ".") = 0 Then GetExtName = "" Exit Function End If intPos = 1 Do intPos = InStr(intPos, ScanString, ".") If intPos = 0 Then Exit Do Else intPos = intPos + 1 intPosSave = intPos - 1 End If Loop GetExtName = Trim$(Mid$(ScanString, intPosSave + 1)) End Function Sub RDB_Convert_Files_To_PDF() Dim sStartPath As String Dim sWhat As String sStartPath = "D:/workspace/clothes-report/data/fankui/output" 'Where? sWhat = "test.log" 'What? result = DigIn(sStartPath) 'First step End Sub Sub RDB_Workbook_To_PDF(fPath As String) Dim FileName As String 'Call the function with the correct arguments. Workbooks.Open fPath FileName = RDB_Create_PDF(ActiveWorkbook, Replace(fPath, ".xlsx", "") & ".pdf", True, True) ActiveWorkbook.Close SaveChanges:=False 'For a fixed file name and to overwrite the file each time you run the macro, use the following statement. 'RDB_Create_PDF(ActiveWorkbook, "C:\Users\Ron\Test\YourPdfFile.pdf", True, True) If FileName <> "" Then 'Uncomment the following statement if you want to send the PDF by mail. 'RDB_Mail_PDF_Outlook FileName, "ron@debruin.nl", "This is the subject", _ "See the attached PDF file with the last figures" _ & vbNewLine & vbNewLine & "Regards Ron de bruin", False Else MsgBox "It is not possible to create the PDF; possible reasons:" & vbNewLine & _ "Microsoft Add-in is not installed" & vbNewLine & _ "You canceled the GetSaveAsFilename dialog" & vbNewLine & _ "The path to save the file in arg 2 is not correct" & vbNewLine & _ "You didn't want to overwrite the existing PDF if it exists." End If End Sub
相关推荐
自己编写的VBAExcel批量转换PDF工具,简易好用!
批量doc转pdf VBA脚本代码
压缩文件中包括一个包含宏代码的Excel文件Sheet Macros.xls以及其他四个测试文件工作表 1~4。 宏的功能为(1)选中Excel表格中的某些行或列,运行某个Macro,自动根据选中的cells创建新的worksheets,worksheets的...
EXCEL VBA PDF 1.使用CreateObject("Wscript.Shell").Run("pdf文件路径") 2.可以使用foxit Activex 或者 adobe 的activex workbookS.open("PDF的路径")
将该文件与需要转换的Excel文件放在同一个文件夹中,打开该文件,点击开始转换,稍等片刻即可完成转换
本资源实现了用VBA(宏)代价遍历文件夹中的csv文件,修改代码也可遍历其他格式的excel文件,并实现了将遍历的结果整合到一个新的excel文件中。
使用 VBA Excel 快速批量修改文件名 1、点击“生成文件名“按钮, 会在 "原文件名"列(A列)生成文件对应的文件名。 2、在"修改后文件名"列(B列)中输入想要修改后的文件名。 3、点击“重命名文件”后即可。 注:...
office利用vba批量转换生成pdf
将Excel工作簿快速、批量转换为PDF电子文档
用VBA批量转换Excel工作簿为.doc
将需要转换的csv文件放到与xls文件同目录下,运行csv2xls宏即可将csv批量转换为xls文件,兼容excel2007 wps2013(需安装vba支持)。文件列表csv2xlsConvert.xls,已编写xls文件,csv2xls.txt宏代码,用法.txt。
Excel VBA批量复制文件到指定目录
ExcelVBA实例教程指南.pdf
ExcelVBA批量转换为pdf文件,无需其他软件,没有任何广告,无任何费用
2.再另外打开你自己需要操作的另一个Excel文件,并保持你要操作的工作表做为当前活动工作表; 3.在你的文件中按Ctrl+I (或在你的文件中手动执行宏,然后选择本EXCEL文件中的宏InsertPic3); 4.然后会出现文件夹选择...
VBA Excel help Document
批量替换ppt内容 VBA脚本代码
EXCEL VBA 读取文本文件宏EXCEL VBA 读取文本文件宏EXCEL VBA 读取文本文件宏
EXCEL VBA编程 单位荣誉证书(支持批量打印)模板
提供参考,批量设置EXCEL文件打印格式,可以使用基本功能,需要优化