fork download
  1. Public Sub 月報_Print()
  2. Dim wb As Workbook
  3. Dim ws As Worksheet
  4. Dim sheet_name As Variant
  5. Dim pPath As String
  6. Dim pFile As String
  7. Dim wsh As Object
  8. Dim p_Name As String
  9. Dim p_FilePath As String
  10. Dim strShCmnd As String
  11.  
  12. Const parent_path = "C:\教えてgoo" 'ご説明されている「リンゴフォルダ」の親フォルダを指定
  13.  
  14. Set wsh = CreateObject("Wscript.Shell")
  15. Set wb = ThisWorkbook
  16. MsgBox "シート選択ダイアログが表示されます。" & vbCrLf & "印刷する月報を選択してください "
  17. Do
  18. wb.Application.CommandBars("Workbook tabs").ShowPopup
  19. DoEvents
  20. sheet_name = Application.InputBox("このシートでいいですか?", , ActiveSheet.Name)
  21. Loop Until sheet_name <> False
  22. Worksheets(sheet_name).PrintOut
  23. pPath = parent_path & "\リンゴ\青森"
  24. p_FilePath = GetLatestPDF(pPath)
  25. p_Name = Application.ActivePrinter
  26. p_Name = Left(p_Name, InStr(p_Name, " on ") - 1)
  27. strShCmnd = "AcroRd32.exe /t " & p_FilePath & " " & p_Name
  28. wsh.Run (strShCmnd)
  29. Application.Wait Now + TimeValue("0:00:10") '10秒待つ
  30. wsh.Exec ("taskkill.exe /F /IM AcroRd32.exe")
  31. Set wsh = Nothing
  32. End Sub
  33. Public Function GetLatestPDF(pPath As String) As String
  34. Dim chkTime As Date
  35. Dim maxTime As Date
  36. Dim chkName As String
  37. Dim maxName As String
  38.  
  39. pPath = pPath & "\"
  40. chkName = Dir(pPath & "*.pdf")
  41. maxTime = FileDateTime(pPath & chkName)
  42. maxName = chkName
  43. Do While chkName <> ""
  44. chkTime = FileDateTime(pPath & chkName)
  45. If chkTime > maxTime Then
  46. maxTime = chkTime
  47. maxName = chkName
  48. End If
  49. chkName = Dir()
  50. Loop
  51. GetLatestPDF = pPath & maxName
  52. End Function
  53.  
  54.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty