Skip to content

Instantly share code, notes, and snippets.

@jacky9813
Last active February 5, 2021 14:20
Show Gist options
  • Save jacky9813/1e59324b06f22df43cfb22e03da6d6b3 to your computer and use it in GitHub Desktop.
Save jacky9813/1e59324b06f22df43cfb22e03da6d6b3 to your computer and use it in GitHub Desktop.
Dim verbose
verbose = True
' verbose = False
Sub WordCallback(FilePath)
On Error Resume Next
Dim outputPath, oDoc
outputPath = FilePath & "x"
If verbose Then
Wscript.Echo FilePath & " => " & outputPath
End If
Set oDoc = objWord.Documents.Open(FilePath)
If Err.Number <> 0 Then
Wscript.Echo "[ERROR] Unable to convert file " & FilePath
Err.Clear
End If
objWord.ActiveDocument.SaveAs outputPath, 12
oDoc.Close
End Sub
Sub ExcelCallback(FilePath)
On Error Resume Next
Dim outputPath
outputPath = FilePath & "x"
If verbose Then
Wscript.Echo FilePath & " => " & outputPath
End If
Set oWb = objExcel.Workbooks.Open(FilePath)
If Err.Number <> 0 Then
Wscript.Echo "[ERROR] Unable to convert file " & FilePath
Err.Clear
End If
objExcel.ActiveWorkbook.SaveAs outputPath, 51
oWb.Close
End Sub
Sub PwrPntCallback(FilePath)
On Error Resume Next
Dim outputPath
outputPath = FilePath & "x"
If verbose Then
Wscript.Echo FilePath & " => " & outputPath
End If
Set oPre = objPwrpnt.Presentations.Open(FilePath)
If Err.Number <> 0 Then
Wscript.Echo "[ERROR] Unable to convert file " & FilePath
Err.Clear
End If
objPwrpnt.ActivePresentation.SaveAs outputPath, 24
oPre.Close
End Sub
Sub WalkThroughFolder(Path)
If verbose Then
Wscript.Echo Path.Path
End If
For Each File In Path.Files
'Get Extension of a file
Select Case LCase(objFSO.GetExtensionName(File.Path))
Case "doc"
WordCallback File.Path
Case "ppt"
PwrPntCallback File.Path
Case "xls"
ExcelCallback File.Path
End Select
Next
For Each SubFolder In Path.SubFolders
WalkThroughFolder SubFolder
Next
End Sub
Dim HostFolder
' Get Folder
Set sh = CreateObject("Shell.Application")
Set objWord = CreateObject("Word.Application")
Set objExcel = CreateObject("Excel.Application")
Set objPwrpnt = CreateObject("PowerPoint.Application")
Set HostFolder = sh.BrowseForFolder(0, "Select a Folder", 0)
If (HostFolder Is Nothing) Then
MsgBox "Cancelled"
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(HostFolder.Self.Path)
WalkThroughFolder objFolder
'Cleaning Application Sessions
objWord.Quit
objPwrpnt.Quit
objExcel.Quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment