Skip to content

Instantly share code, notes, and snippets.

@hedgejanuary
Created June 26, 2018 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hedgejanuary/2838074f754c80b57e8920319e9c3628 to your computer and use it in GitHub Desktop.
Save hedgejanuary/2838074f754c80b57e8920319e9c3628 to your computer and use it in GitHub Desktop.
Exporting a worksheet data to PDF.
Option Explicit
Sub NotificationLetter_ExportToPDF()
Dim Team As String '所属チーム名
Const FirstRow As 4 'データシートの一番初めのデータ
Dim FinalRow As Long 'データベース最終行
Dim i As Long 'カウンタ変数
'データシートの名前を変数に格納
Dim dSheet As String
dSheet = "Database"
'通知書シートの名前を変数に格納
Dim lSheet As String
lSheet = "Letter"
FinalRow = Worksheets(dSheet).Cells(Rows.Count, 1).End(xlUp).Row
Team = Worksheets(lSheet).Cells(17,4).Value
For i = FirstRow to FinalRow
'変数Teamに格納された値とデータシートE列の値が同じ場合、作業を進める。
If Worksheets(dSheet).Cells(i, "E").Value = Team then
With Worksheets(lSheet)
.Cells(3, 2).value = Worksheets(dSheet).Cells(i, 1).value
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "¥" & Year(Now()) & "_Notification_" & Team _
& "_" & Worksheets(dSheet).Cells(i, "C").Value & ".pdf", _
Quality:=xlQualityStandard, _
Includedocproperties:=True, _
Ignoreprintareas:=False, _
openafterpublish:=False
End With
End IF
Next i
MsgBox "通知書が【" & ThisWorkbook.Path & "】フォルダ内に格納されました。"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment