ได้แล้วครับบบบ ขอบคุณครับ น้ำตาไหลเลย พอดีเป็นมือใหม่หัดเริ่ม
ผมแก้ได้เป็นตามนี้ครับ
Code: Select all
Option Explicit
Function FolderExist(Path As String) As Boolean
On Error Resume Next
If Not Dir(Path, vbDirectory) = vbNullString Then
FolderExist = True
End If
On Error GoTo 0
End Function
Sub á¡pdf()
Dim i As Integer
For i = 3 To ThisWorkbook.Worksheets.Count
If FolderExist("D:\Test\" & ThisWorkbook.Worksheets(i).Range("B4").Value & "") Then
ChDir "D:\Test\" & Range("B4").Value & ""
ThisWorkbook.Worksheets(i).Copy
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Test\" & ThisWorkbook.Worksheets(i).Range("B4").Value & "\" & Range("B4").Value & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
ActiveWorkbook.Close False
Else
On Error Resume Next
MkDir "D:\Test\"
MkDir "D:\Test\" & ThisWorkbook.Worksheets(i).Range("B4").Value & ""
ChDir "D:\Test\" & ThisWorkbook.Worksheets(i).Range("B4").Value & ""
ThisWorkbook.Worksheets(i).Copy
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Test\" & ThisWorkbook.Worksheets(i).Range("B4").Value & "\" & Range("B4").Value & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
ActiveWorkbook.Close False
End If
Next i
End Sub
ผมรบกวนถามเพิ่มครับ คือตอนนี้ถ้าผมรัน code
Code: Select all
Sub á¡data()
Dim rall As Range
Dim r As Range
With Sheets("Data")
Set rall = .Range("o2", .Range("o" & .Rows.Count).End(xlUp))
For Each r In rall
Sheets("Temp").Range("b4").Value = r.Value
Sheets("Temp").Copy after:=Sheets("Temp")
ActiveSheet.Name = Range("B4")
Next r
End With
End Sub
เวลาทำงานจะแยกรหัสออกมาจาก form temp worksheet จะเยอะมากๆ แล้ว ผมจึ่งรัน code PDFต่อ คือปลายทางผมอยากได้ แค่ไฟล์ PDF ผมสามารถรวม code ได้เลยไหมครับ
ปล.แก้ไข แนบไฟล์เพิ่มครับ
You do not have the required permissions to view the files attached to this post.