Special requirements for Save As File dialog box

sapka

Board Regular
Joined
Nov 9, 2009
Messages
110
Hello,
I want to open Save As File dialog box in Excel. I need it to have these features:
1) ability to add filters (msoFileDialogSaveAs does not support it)
2) ability to change Save As button text
3) Unicode support

I was able to get all my mentioned functionality with Application.FileDialog(msoFileDialogFilePicker)
Code:
With Application.FileDialog(msoFileDialogFilePicker)
        .Title = “Unice Title”
        .ButtonName = "Unicode button name"
        .Filters.Add "Example (*.txt)", "*.txt"
         ...
End with
but it was not possible to do the same with msoFileDialogSaveAs (filters are not supported).
Now I am trying to get it via APIs [1] [2]. But I am experiencing two problems: (1) dialog box does not look exactly like
msoFileDialogSaveAs one, (2) I do not know how to properly adjust my code in order to be able change Save As button
caption (I need to take something from API set [2]). My code:
Code:
Type OPENFILENAME
     nStructSize     As Long
     hwndOwner       As Long
     hInstance       As Long
     sFilter         As String
     sCustomFilter   As String
     nCustFilterSize As Long
     nFilterIndex    As Long
     sFile           As String
     nFileSize       As Long
     sFileTitle      As String
     nTitleSize      As Long
     sInitDir        As String
     sDlgTitle       As String
     flags           As Long
     nFileOffset     As Integer
     nFileExt        As Integer
     sDefFileExt     As String
     nCustData       As Long
     fnHook          As Long
     sTemplateName   As String
End Type
 
Declare Function GetActiveWindow Lib "user32.dll" () As Long
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
                "GetOpenFileNameA" _
                (pOpenfilename As OPENFILENAME) As Long
Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
                "GetSaveFileNameA" _
                (pOpenfilename As OPENFILENAME) As Long
 
Sub test()
    Dim uOFN As OPENFILENAME
    uOFN.nStructSize = Len(uOFN)
    uOFN.hwndOwner = GetActiveWindow()
    uOFN.sDlgTitle = "Title"
    uOFN.sFilter = "Test filter (*.test)" & vbNullChar & "*.test" & vbNullChar
    uOFN.nFilterIndex = 1
 
    uOFN.sFile = Space$(256) & vbNullChar
    uOFN.nFileSize = Len(uOFN.sFile)
    uOFN.sFileTitle = Space$(256) & vbNullChar
    uOFN.nTitleSize = Len(uOFN.sFileTitle)
    If GetSaveFileName(uOFN) Then
        MsgBox Left(uOFN.sFile, InStr(uOFN.sFile, vbNullChar) - 1), vbInformation
      Else
        MsgBox "Nothing seleted", vbInformation
    End If
End Sub

Can anyone help me?
:confused:
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top