พอดีผมไปเห็นวิธี save file pdf โดยไม่ต้องระบุตำแหน่งที่ตั้ง File จากเว็บนี้ครับ
http://www.contextures.com/excelvbapdf.html จะเอามาปรับใช้แล้วพบปัญหาดังนี้ครับ
1.ตัวข้อมูลชื่อวิทยากร ตารางสรุปประเมินความพึงพอใจ สามารถ save ออก PDF ได้ตามจำนวนชื่อวิทยากร แต่ข้อมูลออกมาแค่ชื่อคนเดี่ยว คนแรก ตัวอย่าง File ครับ
Sheet1_25590918_2017.pdf
รบกวนขอวิธีให้สามารถออกมาทั้งหมดครับ
2.จากข้อ 1 ข้อมูล PDF ยังไม่ได้มีการปรับ Format กระดาษ
Code: Select all
ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
โด้ดตัวนี้มาจากการบันทึก Macro ไม่ทราบว่าจะเอาเพิ่มไว้ตรงไหน ทดลองแทรกอยู่หลายครั้งแต่ติด Error ครับ จะได้ช่วยปรับหน้ากระดาษ PDF ให้ ตารางหรือตัวอักษรที่ตกไปอยู่หน้าอื่น ดันขึ้นมาอยู่ในหน้าเดี่ยวกันครับ
จากตัวอย่างครับ Sheet ตารางสรุปประเมินความพึงพอใจ ชื่อปุ่ม Form_PDF Module 6 Code ดังกล่าว
Code: Select all
Sub Button10_PDF()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Dim allV As Range
Dim r As Range
Dim ns As Worksheet
Dim s As Range
Dim myValue As Variant
Set ns = Sheets.Add(After:=ActiveSheet)
Set s = Sheets("สรุปวิทยากรตามหลักสูตร").Range("b7")
With Sheets("ตารางสรุปประเมินความพึงพอใจ")
Set allV = .Range("c11", .Range("c" & .Rows.Count).End(xlUp))
End With
For Each r In allV
s.Value = r.Value
Sheets("สรุปวิทยากรตามหลักสูตร").UsedRange.Copy
With ns.Range("c" & Rows.Count).End(xlUp).Offset(1, -2)
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "yyyymmdd\_hhmm")
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")
'create default name for savng file
strFile = strName & "_" & strTime & ".pdf"
strPathFile = strPath & strFile
'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
'export to PDF if a folder was selected
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If
End With
Application.CutCopyMode = False
Next r
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
Sheets("ตารางสรุปประเมินความพึงพอใจ").Select
End Sub
ปรับปรุง_ตารางสถิติความพึงพอใจวิทยากร.xlsm
รบกวนด้วยครับขอบคุณครับ
You do not have the required permissions to view the files attached to this post.