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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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