snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub index01ToPdf()
Dim sFolderPath As String
Dim Path As String
Dim FName As String
On Error Resume Next
With ActiveSheet.PageSetup
.Zoom = 98
End With
Application.ScreenUpdating = False
sFolderPath = "C:\" & Range("B16").Value
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
sFolderPath = "C:\" & Range("B16").Value & "\" & Range("B17").Value
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
sFolderPath = "C:\" & Range("B16").Value & "\" & Range("B17").Value & "\" & "PDF"
If Dir(sFolderPath, vbDirectory) = "" Then
MkDir sFolderPath
End If
FName = ActiveSheet.Range("B18") & ActiveSheet.Range("B19") & ".PDF"
Application.DisplayAlerts = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFolderPath & "\" & FName
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "บันทึกไฟล์ไว้ที่" & "C:\" & Range("B16").Value & "\" & Range("B17").Value & "\" & "PDF" & "\" & FName
End Sub