Convert Older Office Format to New Format

email me

I created a script that will convert office file formats from older to newer formats.

Script

‘SET PATH LOCATION
””””””””””””””””””””””””””””””””””””””””””
thePATH=”C:\myFilesPath”
””””””””””””””””””””””””””””””””””””””””””
””””””””””””””””””””””””””””””””””””””””””
‘Created by Eddie Jackson
‘Date: 11/3/2014
‘Used to convert office file formats
‘from older to newer formats in the
‘same folder
‘Usage: update files path above
‘run _RUNME.vbs
””””””””””””””””””””””””””””””””””””””””””

on error resume next
SET objShell = CreateObject(“WScript.Shell”)
SET FSO = CreateObject(“Scripting.FileSystemObject”)

CONST ForReading = 1
CONST ForWriting = 2

IF NOT (fso.FileExists(“C:\scripts\Office_Converter\FileFormatConverters.exe”)) THEN
Msgbox “Missing Files!”
Wscript.Quit(0)
END IF

IF NOT (fso.FileExists(“C:\scripts\Office_Converter\ofc.exe”)) THEN
Msgbox “Missing Files!”
Wscript.Quit(0)
END IF

IF NOT (fso.FileExists(“C:\scripts\Office_Converter\comptool.dll”)) THEN
Msgbox “Missing Files!”
Wscript.Quit(0)
END IF

IF NOT (fso.FileExists(“C:\scripts\Office_Converter\vet.exe”)) THEN
Msgbox “Missing Files!”
Wscript.Quit(0)
END IF

IF NOT (fso.FileExists(“C:\scripts\Office_Converter\template.ini”)) THEN
Msgbox “Missing Files!”
Wscript.Quit(0)
END IF

‘INSTALLS FILE CONVERTERS IF NEEDED
IF NOT (fso.FileExists(“C:\Program Files (x86)\Microsoft Office\Office12\excelcnv.exe”)) THEN
objShell.Run “C:\scripts\Office_Converter\FileFormatConverters.exe /quiet /norestart”,0,true
END IF

‘COPIES TEMPLATE INI FILE
objShell.Run “%comspec% /c copy /y C:\scripts\Office_Converter\template.ini C:\scripts\Office_Converter\ofc.ini”,0,true
SET objFile = FSO.OpenTextFile(“C:\scripts\Office_Converter\ofc.ini”, ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, “zzzzz“, thePATH)

‘UPDATES OFC.INI WITH FILES NAME
SET objFile = FSO.OpenTextFile(“C:\scripts\Office_Converter\ofc.ini”, ForWriting)
objFile.WriteLine strNewText
objFile.Close

‘RUNS CONVERTER – GENERATES XLSX FILES
objShell.Run “C:\scripts\Office_Converter\ofc.exe”,0,TRUE

‘REMOVES OLD XLS FILES

strExtensionsToDelete = “xls”
‘strExtensionsToDelete = “wav,avi,mp3″

RecursiveDeleteByExtension thePATH,strExtensionsToDelete

SUB RecursiveDeleteByExtension(byval strDirectory,strExtensionsToDelete)
DIM objFolder, objSubFolder, objFile
DIM strExt

SET objFolder = FSO.GetFolder(strDirectory)
FOR EACH objFile IN objFolder.Files
FOR EACH strExt IN SPLIT(UCASE(strExtensionsToDelete),”,”)
IF RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = “.” & strExt THEN
‘wscript.echo “Deleting:” & objFile.Path
objFile.Delete
EXIT FOR
END IF
NEXT
NEXT
FOR EACH objSubFolder IN objFolder.SubFolders
RecursiveDeleteByExtension objSubFolder.Path,strExtensionsToDelete
NEXT
END SUB

 

 

The template.ini

;Please refer to the online documentation for more information.

[Run]
; LogDestinationPath: the path where the log files will be written to
LogDestinationPath=C:\scripts\Office_Converter\logs

; Description: this can be any text to describe extra information about the run
;Description= “Test run of the Office File Converter”

; FileListFolder: the folder containing the File List exported from the OMPM Reporting Tool
; (do not include if specifying FoldersToConvert)
;FileListFolder=dataexport\list1\

; TimeOut: a limit in seconds for the conversion of a single file. (default 300 seconds)
; If expired, the Office File Converter will cancel the conversion of the current file and move on to the next file.
; Conversion will never timeout if this value is set to 0.
; Set to a higher value if experiencing difficulties with larger files.
TimeOut = 300

[ConversionOptions]
; FullUpgradeOnOpen: if set to 1, Word documents will be fully converted to the OpenXML format
; if set to 0 (default), Word documents will be saved in the OpenXML format in compatibility mode
; Not applicable to Excel or PowerPoint files.
FullUpgradeOnOpen=1

; CABLogs: if set to 1 (default), XML log files will be compressed into CAB files
; if set to 0, XML log files will be written separately
CABLogs=1

; MacroControl: if set to 1, VBA projects will not be included in converted files
; if set to 0 (default), VBA projects will be maintained in the converted files
MacroControl=0

[FoldersToConvert]
; The Converter will attempt to convert all supported files in the specified folders
; (do not include if specifying FileListFolder)
;fldr=C:\Documents and Settings\Administrator\My Documents
fldr=zzzzz

[ConversionInfo]
; Use SourcePathTemplate and DestinationPathTemplate to specify the destination folder structure.

; SourcePathTemplate: a sequence of ‘*\’ that determines how many directories from the source path will be captured.
; DestinationPathTemplate: path where converted files will be saved, possibly including captured folder names from the SourcePathTemplate
; The converted file will be saved at: DestinationPathTemplate + Remaining uncaptured source path
;
; For example:
; Source files are contained in \\userfiles\[user name]\docs\
; Desired output is to \\newserver\docs\[user name]\
;
; The following settings would enable this example scenario:
; SourcePathTemplate = *\*\*\
; DestinationPathTemplate = \\newserver\*3\*2
; Explanation: The first three folder names are captured in order (“*X” designates which captured folder name to use):
; *1 = userfiles
; *2 = [user name]
; *3 = docs
; Here are some sample file source files and converted files for this example:
; \\userfiles\Bob\docs\Personal\Rept1.doc => \\newserver\docs\Bob\Personal\Rept1.docx
; \\userfiles\James\docs\New Folder\Schedule.doc => \\newserver\docs\James\New Folder\Schedule.docx
; \\userfiles\Cliff\docs\notes.doc => \\newserver\docs\Cliff\notes.docx
;
; Please refer to the online documentation for more information and examples.

SourcePathTemplate=*\*\*\*\*\
DestinationPathTemplate=*1\*2\*3\*4\*5