snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub printpdf()
Dim sFolderPath As String
Dim FName As String
Dim fdObj As Object
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set fdObj = CreateObject("Scripting.FileSystemObject")
fdObj.CreateFolder ("C:\" & Range("A2").Value)
sFolderPath = "C:\" & Range("A2").Value
FName = Range("A1").Value & ".PDF"
' If Sheet1.Range("J1").Value > 38 Then
Sheets(Array("sheet2", "sheet3", "sheet4", "sheet5", "sheet6")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFolderPath & "\" & FName
Sheet1.Select
' End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Print OK"
End Sub
Sub printpdf()
Dim sFolderPath As String
Dim FName As String
Dim fdObj As Object
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set fdObj = CreateObject("Scripting.FileSystemObject")
fdObj.CreateFolder ("C:\" & Range("A2").Value)
sFolderPath = "C:\" & Range("A2").Value
FName = Range("A1").Value & ".PDF"
If Sheet1.Range("J1").Value > 38 Then
Sheets(Array("sheet2", "sheet3", "sheet4", "sheet5", "sheet6")).Select
Else
With Sheets("Sheet2")
With .PageSetup
.PrintArea = "A2:J38"
.FitToPagesTall = 1
End With
.Select
End With
End If
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFolderPath & "\" & FName
Sheet1.Select
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Print OK"
End Sub