Log in

View Full Version : [SOLVED:] SaveAs Filter



sts023
11-12-2013, 10:22 AM
Hi Guys....

I've been trying to write Word 2010 code to execute a "Save As" dialogue, but using Filters.
I'm in a Template, intercepting Save and Save As commandsds in order to offer a likely Filename and Path (based on the content in the Document).

I've done A LOT of Googling trying to find out how to circumvent the apparent oversight of Word VBA not supporting Filters, but to no avail.

I want to preset the SaveAs dialogue box to "*.docm" instead of "*.docx".

Can anyone point me at an example?

sts023
11-12-2013, 10:39 AM
OK - for once I found the answer myself using the following diagnostic code

Sub Main()
Dim fdfs As FileDialogFilters
Dim fdf As FileDialogFilter
Dim fd As FileDialog
Dim intMax As Integer
Dim strMsg As String
strMsg = ""
'Set the FileDialogFilters collection variable to
'the FileDialogFilters collection of the SaveAs dialog box.
Set fd = Application.FileDialog(msoFileDialogSaveAs)
Set fdfs = fd.Filters
' Set fdfs = Application.FileDialog(msoFileDialogSaveAs).Filters
'Iterate through the description and extensions of each
'default filter in the SaveAs dialog box.
intMax = 0
For Each fdf In fdfs
intMax = intMax + 1
'Display the description of filters that include
'Microsoft Excel files.
If InStr(1, fdf.Extensions, "do", vbTextCompare) > 0 Then
strMsg = strMsg & _
intMax & ": (" & _
fdf.Extensions & ") " & _
fdf.Description & _
vbCrLf
End If
Next fdf
Call MsgBox("Analysis of " & intMax & " filters: " & vbCrLf & _
strMsg, vbInformation, "DIAGNOSTIC")
fd.FilterIndex = 2
fd.Show
End Sub



There may be more elegant ways, other than determining the filters position in the list, but I haven't been able to find any....