, , UserForm.Tag, .
, UserForm , UserForm , UserForm.
Select_Email_Template UserForm:
Private Sub UserForm_Initialize()
Dim varTemplateName As Variant
With ComboBox1
For Each varTemplateName In Templates(NameOnly:=True) ' Templates() also works
.AddItem varTemplateName
Next
End With
End Sub
Private Sub btnOK_Click()
Me.Tag = Me.ComboBox1.ListIndex
Me.Hide
End Sub
Private Sub btnCancel_Click()
Me.Tag = -1
Me.Hide
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = VBA.VbQueryClose.vbFormControlMenu Then
Cancel = True
btnCancel_Click
End If
End Sub
-:
Public Sub Email_Templates()
With Select_Email_Template
.Show
If .Tag <> -1 Then
CreateItemFromTemplate(Templates(.Tag, FullPath:=True)).Display ' Templates(.Tag) also works
End If
End With
Unload Select_Email_Template
End Sub
Public Function Templates _
( _
Optional ByVal plngIndex As Long = -1 _
, Optional ByVal NameOnly As Boolean = False _
, Optional ByVal FullPath As Boolean = False _
) _
As Variant
Const strcTemplatesDir As String = "<TemplatesPath>\"
Const strcTemplateExtension As String = ".oft"
Static avarTemplateNames As Variant
If IsEmpty(avarTemplateNames) Then
avarTemplateNames = Array _
( _
"Account Amendment Non SC" _
, "Account Amendment SC Application Received" _
, "Account Amendment SC" _
, "Account Creation Non SC" _
, "Account Creation SC Application Received" _
, "Account Creation SC" _
, "Export Function" _
, "Export Function" _
)
End If
If plngIndex <> -1 Then
If NameOnly = True And FullPath = False Then
Templates = avarTemplateNames(plngIndex)
Else
Templates = strcTemplatesDir & avarTemplateNames(plngIndex) & strcTemplateExtension
End If
Else
Templates = avarTemplateNames
End If
End Function
:
- Select_Email_Template.Tag -1, Cancel ( 0 7 ), OK.
ALT + F4, ( ALT + SPC; C) UserForm, .
, , .. Templates().
, . Dim , .
. , RVBA.