Nevermind...
If you have this problem here is how I solved it:
1.- You have to add a member variable in Joacim's Class under the comment "'local variable(s) to hold property value(s)":
VB Code:
Private m_FilterIndex As Long
2.- You have to add a Let Property and a Get Property named "FilterIndex", it would be better if it was under the "Filter" Let and Get Properties:
VB Code:
Public Property Get FilterIndex() As Long
FilterIndex = m_FilterIndex
End Property
Public Property Let FilterIndex(ByVal lFilterIndex As Long)
m_FilterIndex = lFilterIndex
End Property
3.- You have to edit the ShowSave function so it would be like this:
VB Code:
Public Function ShowSave() As Boolean
Dim ofn As OPENFILENAME
Dim nRetVal As Long
If m_FilterIndex = 0 Then m_FilterIndex = 1 'Added for FilterIndex
With ofn
.lStructSize = Len(ofn)
.hwndOwner = m_Owner.hWnd
.hInstance = App.hInstance
.lpstrFilter = VBA.Replace$(m_Filter, "|", Chr$(0)) & Chr$(0)
.nFilterIndex = m_FilterIndex 'Added for FilterIndex
.nMaxFile = MAX_PATH + 1
.nMaxFileTitle = MAX_PATH + 1
.lpstrFileTitle = Space$(MAX_PATH)
.lpstrInitialDir = CurDir$
.lpstrFile = Me.FileName & Space$(MAX_PATH - Len(Me.FileName))
.lpstrTitle = m_Title
.flags = &H800 + &H4 + &H200000 + &H2 'PathMustExist + HideReadOnly + LongNames + OverwritePrompt
.lpstrDefExt = m_DefExt
End With
nRetVal = GetSaveFileName(ofn)
If nRetVal Then
m_FileTitle = ofn.lpstrFileTitle
m_FileName = ofn.lpstrFile
m_Path = Left$(m_FileName, InStrRev(m_FileName, "\") - 1)
m_FilterIndex = ofn.nFilterIndex 'Added for FilterIndex
End If
ShowSave = (nRetVal > 0)
End Function
4.- You have to edit the ShowOpen as well:
VB Code:
Public Function ShowOpen() As Boolean
Dim ofn As OPENFILENAME
Dim nRetVal As Long
If m_FilterIndex = 0 Then m_FilterIndex = 1 'Added For FilterIndex
With ofn
.lStructSize = Len(ofn)
.hwndOwner = m_Owner.hWnd
.hInstance = App.hInstance
.lpstrFilter = VBA.Replace$(m_Filter, "|", Chr$(0)) & Chr$(0)
.nMaxFile = MAX_PATH + 1
.nMaxFileTitle = MAX_PATH + 1
.nFilterIndex = m_FilterIndex 'Added For FilterIndex
.lpstrFileTitle = Space$(MAX_PATH)
.lpstrInitialDir = CurDir$ 'Manavo's
.lpstrFile = Me.FileName & Space$(MAX_PATH - Len(Me.FileName))
.lpstrTitle = m_Title
.flags = &H1000 + &H4 + &H200000 'FileMustExist + HideReadOnly + LongNames
.lpstrDefExt = m_DefExt
End With
nRetVal = GetOpenFileName(ofn)
If nRetVal Then
m_FileTitle = ofn.lpstrFileTitle
m_FileName = Left$(ofn.lpstrFile, InStr(ofn.lpstrFile, Chr$(0)) - 1)
m_Path = Left$(m_FileName, InStrRev(m_FileName, "\") - 1)
m_FilterIndex = ofn.nFilterIndex 'Added For FilterIndex
End If
ShowOpen = (nRetVal > 0)
End Function
And that's it. Now you can use the FilterIndex property to know which was the filter they chose.
Now, regarding the problem of saving the file without the extension, you have to do this trick when you call the ShowSave function:
VB Code:
Dim cmnDlg As CCommonDialogs
Set cmnDlg = New CCommonDialogs
With cmnDlg
.Init Me
.Path = App.Path
.Filter = "HTML Document (*.htm) | *.htm| Rich Text Format (*.rtf)| *.rtf"
.FileName = ""
.DefExt = ".force" 'Force the dialog to use the extensions.
If .ShowSave Then
'Your Code here
End If
End With
Set cmnDlg = Nothing