Class FileConverter (Word VBA)
The class FileConverter represents a file converter that's used to open or save files. The FileConverter object is a member of the FileConverters collection. The FileConverters collection contains all the installed file converters for opening and saving files. To use a FileConverter class variable it first needs to be instantiated, for example
Dim fcr as FileConverter
Set fcr = FileConverters(Index:=1)
For Each
Here is an example of processing the FileConverter items in a collection.
Dim fcr As FileConverter
For Each fcr In FileConverters
If fcr.CanOpen = True Then MsgBox fcr.OpenFormat & vbCr & fcr.FormatName
Next fcr
CanOpen
True if the specified file converter is designed to open files.
The CanSave property returns True if the specified file converter can be used to save (export) files.
If FileConverters(1).CanOpen = True Then
MsgBox FileConverters(1).FormatName & " can open files"
End If
CanSave
True if the specified file converter is designed to save files.
The CanOpen property returns True if the specified file converter can be used to open (import) files.
Dim lngSaveFormat As Long
If Application.FileConverters("WordPerfect6x").CanSave = _
True Then
lngSaveFormat = _
Application.FileConverters("WordPerfect6x").SaveFormat
ActiveDocument.SaveAs FileName:="C:\Document.wp", _
FileFormat:=lngSaveFormat
End If
ClassName
Returns a unique name that identifies the file converter.
MsgBox "ClassName= " & FileConverters(1).ClassName & vbCr _
& "FormatName= " & FileConverters(1).FormatName
Extensions
Returns the file name extensions associated with the specified FileConverter object.
Dim fcTemp As FileConverter
Set fcTemp = FileConverters(1)
MsgBox "The file name extensions for " & fcTemp.FormatName _
& " files are: " & fcTemp.Extensions
FormatName
Returns the name of the specified file converter.
The format names appear in the Save as type box in the Save As dialog box (File menu).
MsgBox FileConverters(1).FormatName
Name
Returns name of the specified object.
Dim strName As String
strName = FileConverters(1).Name
OpenFormat
Returns the file format of the specified file converter.
This property can be any valid WdOpenFormat constant, or it can be a unique number that represents an external file converter.
For Each fc In FileConverters
If fc.CanOpen = True Then _
MsgBox fc.OpenFormat & vbCr & fc.FormatName
Next fc
Path
Returns the disk or Web path to the specified object.
The path doesn't include a trailing character — for example, "C:\MSOffice" or "https://MyServer". Use the PathSeparator property to add the character that separates folders and drive letters. Use the Name property to return the file name without the path. You can create the full name of a file converter by concatenating the Path, PathSeparator, and Name properties.
Dim strPath As String
strPath = FileConverters(1).Path
SaveFormat
Returns the file format of the specified document or file converter.
This property returns a unique number that specifies an external file converter or a WdSaveFormat constant. Use the value of the SaveFormat property for the FileFormat argument of the SaveAs2 method to save a document in a file format for which there isn't a corresponding WdSaveFormat constant.
Sub FileConverterList()
Dim cnvFile As FileConverter
Dim docNew As Document
'Create a new document and set a tab stop
Set docNew = Documents.Add
docNew.Paragraphs.Format.TabStops.Add _
Position:=InchesToPoints(3)
'List all the converters in the FileConverters collection
With docNew.Content
.InsertAfter "Name" & vbTab & "Number"
.InsertParagraphAfter
For Each cnvFile In FileConverters
If cnvFile.CanSave = True Then
.InsertAfter cnvFile.FormatName & vbTab & _
cnvFile.SaveFormat
.InsertParagraphAfter
End If
Next
.ConvertToTable
End With
End Sub