- Tham gia
- 17/8/08
- Bài viết
- 8,662
- Được thích
- 16,722
- Giới tính
- Nam
Nhằm thuận tiện cho việc gửi file hàng loạt qua mail, tôi làm cái thủ tục này để phục vụ công việc và chia sẻ cho mọi người nếu cần thiết. Nếu ai có bổ sung gì thêm xin vui lòng góp ý.
Mã:
Public Sub PDFCreater(ByVal strPath As String, ByVal strFileName As String, ByVal rngCreatePDF As Range)
Dim objFSO As Object
Dim strFullNameFileSaved As String
strPath = Trim(strPath): strFileName = Trim(strFileName)
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
If LCase(Right(strFileName, 4)) <> ".pdf" Then strFileName = strFileName & ".pdf"
strFullNameFileSaved = strPath & strFileName
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If objFSO.FileExists(strFullNameFileSaved) Then objFSO.DeleteFile strFullNameFileSaved
If Err.Number Then
MsgBox "The old file PDF is opening, please close it!", vbCritical + vbOKOnly
Set objFSO = Nothing
Exit Sub
End If
rngCreatePDF.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=strFullNameFileSaved, _
IncludeDocProperties:=True, _
Quality:=xlQualityStandard, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Set objFSO = Nothing
End Sub
Sub Test()
PDFCreater ThisWorkbook.Path, "ThiNghiem", Selection
End Sub
Lần chỉnh sửa cuối: