【发布时间】:2020-06-24 03:57:43
【问题描述】:
我目前被困在如何实现在 VBA 中获取和存储信息的过程。
目标:
- 获取要分配任务的代理列表。
- 获取每个代理的任务列表(票号)
- 将信息格式化为已定义的电子邮件回复结构
目前,我有一个函数可以获取代理名称 (isagent(sAgent)) 并对其进行验证,获取票号 (Incident()) 并对其进行验证,以及使用要格式化的字符串回复消息的功能消息(sBody)。
问题:
输入数据的存储容器是我的保留。我不认为数组是一个正确的选择,因为代理的数量和每个代理的票数每天都会波动。
例如: 昨天的请求:将 123 票重新分配给第 1 个人
今天的请求 - 将工单 123、456 和 789 重新分配给第 1 个人。将 012 重新分配给第 2 个人,将 345、678、901、234 和 567 重新分配给第 3 个人
格式:
存储数据的格式需要这样返回:
示例 - 昨天的请求:123 已重新分配给 person1。 今天的请求: 123、456 和 789 已重新分配给人员 1。 012 已重新分配给第 2 个人。 345、678、901、234 和 567 已重新分配给第 3 个人
代码:
此部分为Message body格式,可以组合成一个字符串(sBody)。变量当前设置为 sIncs 代表票号,sXferAgent 代表代理,sTense 代表句子时态。
'Set Body Reply
Dim sOpen, sBody, sAddendum, sClose As String 'Message Reply Format
sOpen = "<span style=""font-size:11.0pt;font-family:"Calibri",sans-serif;mso-bidi-font-family:" & vbCrLf & _
"Arial"">Team, <o:p></o:p></span>" & vbCrLf
sBody = "<p><span style=""font-size:11.0pt;font-family:"Calibri",sans-serif;mso-bidi-font-family:" & vbCrLf & _
"Arial"">" & sINCs & " " & sTense & " been created and assigned to " & sXferAgent & "<o:p></o:p></span></p>" & vbCrLf
sClose = "<p><span style=""font-size:11.0pt;font-family:"Calibri",sans-serif;mso-bidi-font-family:" & vbCrLf & _
"Arial"">Thanks & Regards,<o:p></o:p></span></p>" & vbCrLf & _
"<p><br/></p>"
olMsgReplyAll.HTMLBody = sOpen & sBody & sClose & sSig & olMsgReplyAll.HTMLBody
要获得票证和代理格式,我是这样称呼它们的:
Dim sInc As String
'Receive Incident Number as AlphaNumeric
sInc = Incident()
If sInc = "" Then
Exit Sub
End If
'Receive Agent Name
sAgent = ValidateAgent
If sAgent = "" Then
Exit Sub
End If
目前,我的半傻想法如下:
Sub Handoff()
'Get reassigned tickets in loop
'Asks for how many agents, ticket count per agent, gathers agent name and tickets for agent
'Functions in place for get agent name, and ticket number preformatted
'storage container issues for above process
'Formats data into separate lines with verbiage
Dim colReassignments As New Collection 'container for all reassignments
Dim colAgents As New Collection 'container for agents
Dim colTickets As New Collection 'container for tickets
Dim ReassignCount As Integer '# of tickets for the agent
Dim ReassignAgent As Integer 'Agents to reassign to
Dim Reassignments() As String
'Start inquiry
ReassignAgent = InputBox("Input number of Agents tickets being reassigned to:", "Agent Counter")
If ReassignAgent = vbNullString Then
Exit Sub
End If
While ReassignAgent > 0
colAgents.Add = ValidateAgent
ReassignCount = InputBox("Input number of ticket being reassigned to agent:", "Ticket Counter")
If ReassignCount = vbNullString Then
Exit Sub
End If
For Each agent In colAgents
For Each ticket In colTickets
agent(x).ticket(y) = Incident()
If agent(x).ticket(y) = "" Then
Exit Sub
End If
agent(x) = ValidateAgent
If agent(x) = "" Then
Exit Sub
End If
ReassignCount = ReassignCount - 1
Next ticket
Next agent
Wend
'Sentence Formatting
'Get Tense of reassignment
If ReassignCount > 1 Then
tense = "have"
Else
tense = "has"
End If
'Compile stored info
'Format: "(Ticket#(s)) (tense) been reassigned to (Agent)" repeat lines as necessary
'Process email
'In another module
End Sub
非常感谢任何建议或意见。我可能把问题复杂化了。
更新以反映其他模块:
'Function to get ticket number
Public Function Incident()
Dim strPattern As String: strPattern = "^(?:INC|NC|C)?([0-9]{1,8}$)"
Dim strReplaceINC As String: strReplaceINC = "$1"
Dim regEx As New RegExp
Dim strInput As String
Dim IncResult As Boolean
Do
If strPattern <> "" Then
strInput = InputBox("Input Incident Number", "Ticket Number")
If strInput = vbNullString Then
Exit Function
End If
IncResult = False
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = strPattern
End With
If regEx.Test(strInput) Then
sInc = regEx.Replace(strInput, strReplaceINC)
sInc = "INC" & Format(sInc, "00000000")
IncResult = True
Else
MsgBox ("Please input a valid ticket number format")
IncResult = False
End If
End If
Loop While IncResult = False
Incident = sInc
End Function
'Function to select Agent
Public Function IsAgent(stxt As String) As Boolean
Dim aAgent As Variant, oItem As Variant, bans As Boolean
aAgent = Array("Bob", "Chuck", "David", "Fred", "John", "Kirk", "Paul", "Sean")
bans = False
For Each oItem In aAgent
If LCase(oItem) = LCase(Trim(stxt)) Then
bans = True
Exit For
End If
Next
IsAgent = bans
End Function
'Function to Validate Agent
Public Function ValidateAgent()
'Dim sAgent As String 'Assigned Agent
Do
sAgent = InputBox("Please enter a the assigned agent's name:", "Pick an Assignee's Name")
If sAgent = vbNullString Then
Exit Function
End If
If sAgent <> "" Then
If GlobalVars.IsAgent(sAgent) = True Then
sAgent = sAgent
Else
MsgBox ("Incorrect Name, pick a new one!")
End If
End If
Loop While GlobalVars.IsAgent(sAgent) = False
ValidateAgent = sAgent
End Function
【问题讨论】:
-
如果您担心尺寸变化,数组可以是动态的。不过,您只能重新调整最后一个维度。在某些情况下,您可以通过转置暂时/永久地交换最后一个维度来解决这个问题。
-
这是在乞求面向对象的解决方案。
-
注意
Dim sOpen, sBody, sAddendum, sClose As String中只有 sClose 是一个字符串。其余的将是变体。在这样的列表中,您需要在每个变量名之后使用As String。 -
agent(x).ticket(y) = Incident()是做什么的?agent和ticket似乎是简单的变体。我想不出任何方式可以将它们像这样组合在一起。 -
sInc = Incident()和sAgent = ValidateAgent如何工作?
标签: arrays vba collections outlook