2013-06-19 35 views
1

Word VBA中的「另存爲」對話框有客戶過濾器嗎?例如:「.ttt」帶自定義過濾器的Word VBA另存爲對話框?

+0

是否要顯示預定義文件類型的「另存爲」對話框?但它不會將文件轉換爲'.psd',因爲此類型不受字支持... –

+0

.psd文件格式是顯示自定義過濾器的示例。謝謝 –

回答

4

我想你可能想使用Application.FileDialog,因爲這允許自定義文件過濾器。正如KazJaw指出的那樣,您無法在Word中保存Photoshop文件,因此我認爲它允許對psd文件進行一些其他操作。

下面說明如何使用它(請參閱http://msdn.microsoft.com/en-us/library/aa219843%28office.11%29.aspx)。注意這將允許用戶選擇多個文件。

Sub CustomFilter() 
    'Declare a variable for the FileDialog object and one for the selectedItems 
    Dim fd As FileDialog, vSelectedItem As Variant 

    'Create a FileDialog object as a File Picker dialog box. 
    Set fd = Application.FileDialog(msoFileDialogFilePicker) 

    'With the FileDialog 
    With fd 
     .Filters.Clear        'Clear current filters 
     .Filters.Add "Photoshop Files", "*.psd", 1 'Add a filter that has Photoshop Files. 

     If .Show = -1 Then 
      'Step through each String in the FileDialogSelectedItems collection. 
      For Each vSelectedItem In .SelectedItems 
       'Do whatever you want here 
      Next vSelectedItem 
     Else 
      'The user pressed Cancel. 
     End If 
    End With 

    Set fd = Nothing 
End Sub 
+0

.psd文件格式是顯示自定義過濾器的示例。此外,這將工作SAVE AS對話框? –

+0

如果您想使用自定義過濾器(例如.psd或.ttt),則必須使用FileDialog框,否則無法使用帶有SaveAs對話框(默認Word文件類型之外)的自定義過濾器。爲什麼你需要使用SaveAs? (您可以使用FileDialog框來獲取文件名,然後保存。) – CuberChase

+0

但是,該文件必須存在才能使用FileDialog? –