Bước 1. Lấy địa chỉ file doc
Mở file Excel và chạy sub này:
Sub GetFileDOCX()
Dim vFile
vFile = Application.GetOpenFilename("*.DOCX, *.DOCX", , , , True)
For i = 1 To UBound(vFile)
Cells(i, 1) = vFile(i)
Next
End Sub
Trong đó:
Cột A:Địa chỉ file word
Cột C:Địa chỉ folder cần lưu
Cột D:Tên file PDF muốn lưu
Bước 2: Sau khi đã có thông tin file Word thì chạy sub này để convert các file word sang PDF
Dim lRow As Long Dim wordApp As Object Dim i As Long ' Tìm dòng cu?i cùng có d? li?u trong c?t A lRow = Cells(Rows.Count, 1).End(xlUp).Row ' T?o d?i tu?ng Word Set wordApp = CreateObject("Word.Application") ' L?p qua t?ng dòng trong ph?m vi d? li?u For i = 2 To lRow ' Ðu?ng d?n luu tr? PDF Dim pdfPath As String pdfPath = Range("C" & i).Value & "\" & Range("D" & i).Value & ".PDF" ' M? t?p Word wordApp.Documents.Open Range("A" & i).Value ' Hi?n th? ?ng d?ng Word (có th? t?t n?u không mu?n hi?n th?) wordApp.Visible = True wordApp.Activate ' Xu?t t?p Word sang PDF wordApp.ActiveDocument.ExportAsFixedFormat OutputFileName:=pdfPath, _ ExportFormat:=17, _ OpenAfterExport:=False, _ OptimizeFor:=0, _ Range:=0, _ From:=1, To:=1, _ Item:=0, _ IncludeDocProps:=True, _ KeepIRM:=True, _ CreateBookmarks:=0, _ DocStructureTags:=True, _ BitmapMissingFonts:=True, _ UseISO19005_1:=False ' Ðóng t?p Word wordApp.ActiveDocument.Close False Next i ' T?t ?ng d?ng Word wordApp.Quit ' Gi?i phóng b? nh? Set wordApp = Nothing End Sub
Nhận xét
Đăng nhận xét