问题
All, I'm trying to pass the value of a selected item (or items) from a userform into ThisOutlookSession, but cannot pass the string. Grateful for thoughts on where I might be going wrong.
The idea is to populate a listbox with a list of references from a txt file (which works fine), the user will select an item from a list box, and that item will then be appended to the end of the subject line of an outgoing email. (The part of the code which amends the subject line is omitted from the below).
Within ThisOutlookSession:
Public subString As String
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
SubjectAdd.Show
[CODE OMITTED, but the gist of it is item.subject = item.subject & strstring]
End Sub
Within SubjectAdd userform:
Private Sub Append_Click()
Dim i As Long
Dim lngCount As Long
lngCount = 0
For i = 0 To MatterList.ListCount - 1
If MatterList.Selected(i) = True Then
lngCount = lngCount + 1
If lngCount = 1 Then
StrPicks = MatterList.List(i)
Else
StrPicks = StrPicks & " " & MatterList.List(i)
End If
End If
Next i
subString = StrPicks
Me.Hide
lbl_Exit:
Exit Sub
End Sub
回答1:
The Public
variable should work
As an alternative use Tag
property of UserForm
object
In Append_Click()
add a final line before Me.Hide
Me.Tag = StrPicks
Then in Application_ItemSend()
, before any
Unload SubjectAdd
place the following
subject = item.subject & SubjectAdd.Tag
来源:https://stackoverflow.com/questions/50521492/unable-to-pass-value-from-userform-to-module