Created
February 19, 2016 10:50
-
-
Save naichilab/48d9970f1cae8180c4b3 to your computer and use it in GitHub Desktop.
MSExcel、MSWordの文書をショートカットキー一発でPDF出力
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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