fork download
  1. Private Sub CommandButton3_Click() 'PPT削除
  2. Const CELL_FILE_PATH As String = "B3"
  3. ' ファイルパス取得
  4. Dim st As String '変数を宣言する
  5. With Application.FileDialog(msoFileDialogFolderPicker)
  6.  
  7. If .Show = True Then
  8. Range(CELL_FILE_PATH).Value = .SelectedItems(1)
  9.  
  10. PPT削除して保存
  11.  
  12. Else
  13. MsgBox "キャンセル実行"
  14. End If
  15.  
  16. End With
  17.  
  18. End Sub
  19. Sub PPT削除して保存()
  20. Dim FSO As Object
  21. Set FSO = CreateObject("Scripting.FileSystemObject")
  22. Dim strArray() As String
  23. Dim file_count As Long
  24. Dim path As String
  25. Dim PPT_app As Object
  26. Dim pptx_file As String
  27. Dim i As Long
  28. path = Sheets("Excel").Range("B3").Value
  29. file_count = 0
  30. Call get_files(path, FSO, file_count, strArray)
  31. If file_count = 0 Then
  32. MsgBox "pptファイルはありません"
  33. Exit Sub
  34. End If
  35. Set PPT_app = CreateObject("PowerPoint.Application")
  36. PPT_app.Visible = True
  37. For i = 0 To UBound(strArray)
  38. With PPT_app.Presentations.Open(strArray(i))
  39. pptx_file = strArray(i) & "x"
  40. .SaveAs Filename:=pptx_file
  41. .Close
  42. End With
  43. Kill strArray(i) '元ファイル削除
  44. Next
  45. MsgBox "PPT変換し元ファイルは削除しています"
  46. PPT_app.Quit
  47.  
  48. End Sub
  49. '拡張子が.pptのファイル名をサブフォルダも含めて取得する
  50. Private Sub get_files(ByVal path As String, FSO As Object, file_count As Long, strArray() As String)
  51. Dim trgfolder As Object
  52. Dim myfiles As Object
  53. Dim myfile As Object
  54. Dim subfolders As Object
  55. Dim subfolder As Object
  56. Set trgfolder = FSO.getfolder(path)
  57. Set myfiles = trgfolder.files 'ファイル一覧取得
  58. For Each myfile In myfiles '各ファイルを処理
  59. '拡張子が.pptのファイルを取得
  60. If LCase(Right(myfile.Name, 4)) = ".ppt" Then
  61. ReDim Preserve strArray(file_count)
  62. strArray(file_count) = path & "\" & myfile.Name
  63. file_count = file_count + 1
  64. End If
  65. Next
  66. Set subfolders = trgfolder.subfolders 'フォルダ一覧取得
  67. For Each subfolder In subfolders '各サブフォルダを処理
  68. 'サブフォルダ下のファイル名を取得
  69. Call get_files(path & "\" & subfolder.Name, FSO, file_count, strArray)
  70. Next
  71. End Sub
  72.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty