Take a look at the Microsoft.Office.Core.FileDialog
interface and its Filters
property (which is type Microsoft.Office.Core.FileDialogFilters
), where you can add and remove filters. They are included with Visual Studio Tools for Office 12, in Office.dll.
As to getting the correct FileDialog
object, first acquire a Microsoft.Office.Interop.Word.Application instance (usually by creating a new ApplicationClass
or, equivalently, using VBA's CreateObject
) and call it application
. Then do something like the following:
Microsoft.Office.Core.FileDialog dialog = application.get_FileDialog( Microsoft.Office.Core.MsoFileDialogType.msoFileDialogSaveAs );
dialog.Title = "Your Save As Title";
// Set any other properties
dialog.Filters.Add( /* You Filter Here */ );
// Show the dialog with your format filter
if( dialog.Show() != 0 && fileDialog.SelectedItems.Count > 0 )
{
// Either call application.SaveAs( ... ) or use your own saving code.
}
The actual code can either be in a COM Add-In, or an external program that uses COM to open/interact with Word. As to replacing the built-in Save As dialog, you'll also need to handle the Microsoft.Office.Interop.Word.Application.DocumentBeforeSave
event somewhere (VBA, with this code, etc) to intercept the default behavior.
Here's an example 'save as' handler:
private void application_DocumentBeforeSave( Microsoft.Office.Interop.Word.Document document, ref bool saveAsUI, ref bool cancel )
{
// Be sure we are only handling our document
if( document != myDocument )
return;
// Allow regular "Save" behavior, when not showing the "Save As" dialog
if( !saveAsUI )
return;
// Do not allow the default UI behavior; cancel the save and use our own method
saveAsUI = false;
cancel = true;
// Call our own "Save As" method on the document for custom UI
MySaveAsMethod( document );
}