Skip to content

Instantly share code, notes, and snippets.

@naichilab
Created February 19, 2016 10:50
Show Gist options
  • Save naichilab/48d9970f1cae8180c4b3 to your computer and use it in GitHub Desktop.
Save naichilab/48d9970f1cae8180c4b3 to your computer and use it in GitHub Desktop.
MSExcel、MSWordの文書をショートカットキー一発でPDF出力
Attribute VB_Name = "PDF"
Option Explicit
Sub SaveToPDF()
Attribute SaveToPDF.VB_ProcData.VB_Invoke_Func = " \n14"
Dim saveTo As String
saveTo = GetDesktopDir() & Format(Now(), "yyyyMMdd_hhmmss") & ".pdf"
ActiveWorkbook.ExportAsFixedFormat _
Type:=xlTypePDF _
, Filename:=saveTo _
, Quality:=xlQualityStandard _
, OpenAfterPublish:=True
End Sub
Function GetDesktopDir() As String
Dim wsh As Variant
Dim desktop As String
Set wsh = CreateObject("WScript.Shell")
desktop = wsh.SpecialFolders("Desktop") & "\"
Set wsh = Nothing
GetDesktopDir = desktop
End Function
Attribute VB_Name = "PDF"
Option Explicit
Sub SaveToPDF()
Dim saveTo As String
saveTo = GetDesktopDir() & Format(Now(), "yyyyMMdd_hhmmss") & ".pdf"
ActiveDocument.ExportAsFixedFormat _
OutputFileName:=saveTo _
, ExportFormat:=wdExportFormatPDF _
, OpenAfterExport:=True _
, OptimizeFor:=wdExportOptimizeForPrint _
, Range:=wdExportAllDocument
End Sub
Function GetDesktopDir() As String
Dim wsh As Variant
Dim desktop As String
Set wsh = CreateObject("WScript.Shell")
desktop = wsh.SpecialFolders("Desktop") & "\"
Set wsh = Nothing
GetDesktopDir = desktop
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment