Skip to content

Instantly share code, notes, and snippets.

@sheepeeh
Last active July 21, 2016 19:11
Show Gist options
  • Save sheepeeh/08136b91189c9e97a700 to your computer and use it in GitHub Desktop.
Save sheepeeh/08136b91189c9e97a700 to your computer and use it in GitHub Desktop.
Convert WPD to DOCX using a Word macro
Function browseForFolder()
Dim intResult As Integer
Dim strPath As String
'the dialog is displayed to the user
intResult = Application.FileDialog(msoFileDialogFolderPicker).Show
'checks if user has cancled the dialog
If intResult <> 0 Then
'dispaly message box
browseForFolder = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
End If
End Function
Option Explicit
Sub ConvertWPtoDoc()
'
' ConvertWPtoDoc Macro
'
Dim zSourceDir As String
Dim zDestDir As String
Dim zFileToCvt As String
Dim vFileName As Variant
Dim originalDate As Variant
Dim todayDate As Variant
todayDate = Format(Date, "mm/dd/yyyy") 'Get Today's date
'*** Click on C:\ below before running to browse to the correct directory
zSourceDir = browseForFolder 'Browse to to the WordPerfect files
zFileToCvt = Dir(zSourceDir & "\*.wpd") 'Get 1st Filename
Do While zFileToCvt <> ""
Documents.Open _
FileName:=Chr(34) & zSourceDir & "\" & zFileToCvt & Chr(34), _
ConfirmConversions:=False, ReadOnly:=True
vFileName = Split(zFileToCvt, ".wpd") 'Strip file type
'Last modified date for the source file'
originalDate = FileDateTime(zSourceDir & "\" & zFileToCvt)
'Add Conversion date and Original Last Modified date to Comments property'
ActiveDocument.BuiltInDocumentProperties(wdPropertyComments).Value = _
"This document was converted from WPD on " & _
todayDate & " Original creation date: " & originalDate
'Save to *.docx'
ActiveDocument.SaveAs2 _
FileName:=Chr(34) & zSourceDir & "\" & vFileName(0) & ".docx" & Chr(34), _
FileFormat:=wdFormatDocumentDefault
ActiveDocument.Close SaveChanges:=False
zFileToCvt = Dir() 'Get Next Filename
Loop
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment