In Outlook heb ik een userform met twee besturingselementen: een listbox en een commandbutton.
Ik lees een cSV-bestand in om een 2dim matrix te vullen.
De listbox vul ik met de eerste kolom van deze 2dim matrix (dit zijn projecten).
Als ik op de commandbutton klik moet de positie van de listbox (ListinIndex) doorgegeven worden zodat ik de corresponderende waarde uit de tweede kolom kan bepalen (opslaglocatie voor de emails in die projectmap).
Hoe kan ik detecteren of de Commandbutton is ingedrukt en de juiste ListIndex wordt doorgegeven?
In het programma weergegeven met "Wait until the command button is pressed", regel 45
Ik lees een cSV-bestand in om een 2dim matrix te vullen.
De listbox vul ik met de eerste kolom van deze 2dim matrix (dit zijn projecten).
Als ik op de commandbutton klik moet de positie van de listbox (ListinIndex) doorgegeven worden zodat ik de corresponderende waarde uit de tweede kolom kan bepalen (opslaglocatie voor de emails in die projectmap).
Hoe kan ik detecteren of de Commandbutton is ingedrukt en de juiste ListIndex wordt doorgegeven?
In het programma weergegeven met "Wait until the command button is pressed", regel 45
Code:
'This program uses an Userform with Listbox and Commandbutton
'=======================================================================================
'Declaration of parameters
Dim myItem As Object
Dim olMail As Outlook.MailItem
Dim Selection As Selection
Dim n As Integer
Dim myFolder As Folder
Dim strSender, strReceiver As String
Dim strDate As Long
Dim strPath As String
Dim choice As Integer
Dim file As String, strLine As String
Dim strDest(1 To 2, 1 To 5) As String '2dim matrix with finally destination for e-mails
Public intChoice As Integer
'=======================================================================================
Sub MailtoFile()
'Read setup file/parameters for dropbox
file = "D:\Setup.csv"
Open file For Input As #1
n = 0
Userform1.ListBox2.Clear
Do Until EOF(1)
n = n + 1
Line Input #1, strLine: 'Debug.Print strLine
pos1 = InStr(strLine, ";")
strDest(1, n) = Left(strLine, pos1 - 1)
Userform1.ListBox2.AddItem (strDest(1, n)) 'Listbox will be filled
strDest(2, n) = Mid(strLine, pos1 + 1)
Loop
Close #1
Debug.Print strDest(1, 4) & " " & strDest(2, 4)
intChoice = 0
Userform1.Show
'Wait until the command button is pressed
If intChoice > 0 Then
'Show value in second column
strPath = strDest(2, Userform1.ListBox2.ListIndex + 1)
MsgBox strPath
End If
End Sub