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)
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:
Can anyone help me?
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
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?