你们都非常乐于助人,我想知道我是否会对你有所帮助。我几乎完成了从VB.net到VBA for Outlook的转换,为了完成这一点,我需要一些关于特定代码片段返回的信息。如果你们都可以帮忙解决这个问题,问题可能就会消失;如果没有,我可能需要一些关于此无效限定符错误的帮助。
据我所知,我在VBA中使用如下命令声明了一个'数组':
Dim Computers(1, 1) As String
产生2x2阵列。然后我试着像这样填写:
Computers.Add ComputerName, ErrorState
其中ComputerName和ErrorState是我已填充的变量。这导致错误。我将为您提供以下完整的相关部分。我需要知道Outlook收件箱中有多少相关项目,这意味着检查它们是在今天的日期和正确的发件人发送的。我需要这个才能在阵列计算机上获得正确的尺寸。 (现在正在填充数组,因为我知道正确的尺寸,但实际上我不会。)我拿了一段代码,我通过google,Scripting Dictionary输出找到了,但我不完全理解它。我只需要电子邮件的数量,没有任何不相关的文本,我希望调试行能够告诉我哪个命令我需要返回数字而没有别的。不幸的是,由于上述错误,我无法达到这条线。即使通过单步执行代码,它首先告诉我的是这里存在问题。整个相关部分如下。我知道格式化是有问题的,但我只使用VB.NET 4天,这是我使用VBA的第二天,所以我还没有完成任何事情。这里有一些无关紧要的东西,我很确定,但是我没有经验来调用是否有相关的东西,所以我把它全部留下了。抱歉这个长度!
Private Sub Main()
Dim objOutlook As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object
Dim strDate As String
Dim ComputerName As Object
Dim ErrorState As Object
Dim DateToday As String: DateToday = Format(Date, "yyyy/MM/dd")
Dim SenderEmail As String
Dim Computers(1, 1) As String
Dim compLength As Integer
Dim disabledList As Collection
Dim enabledList As Collection
Dim unknownList As Collection
Dim notpresentList As Collection
Dim problemList As Collection
Dim cArrayLength As Integer
Dim I As Integer
Dim J As Integer
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim EmailCount As Integer
Dim compArray() As String
'\\ load csv declarations
Dim file_name As String
Dim fnum As Integer
Dim whole_file As String
Dim lines As Variant
Dim one_line As Variant
Dim num_rows As Long
Dim num_cols As Long
Dim R As Long
Dim C As Long
Set disabledList = New Collection
Set enabledList = New Collection
Set unknownList = New Collection
Set notpresentList = New Collection
Set problemList = New Collection
'\\\\\
'\\Retrieve info from outlook, add to sorted list Computers
'\\\\\
objOutlook = CreateObject("Outlook.Application")
Inbox = objOutlook.GetNamespace("Mapi").GetDefaultFolder(6)
InboxItems = Inbox.Items
InboxItems.SetColumns ("SentOn")
Dim myItems As Outlook.Items
Dim dict As Object
Dim msg As String
Set dict = CreateObject("Scripting.Dictionary")
myItems.SetColumns ("SentOn")
EmailCount = InboxItems.Count
For Each Mailobject In InboxItems
strDate = GetDate(Mailobject.SentOn)
If Not dict.Exists(strDate) Then
dict(strDate) = 0
End If
dict(strDate) = CLng(dict(strDate)) + 1
Next Mailobject
'\\ need redo to assign number of objects to CompLength
msg = ""
For Each o In dict.Keys
msg = msg & o & ": " & dict(o) & " items" & vbCrLf
Next
Debug.Print msg
For Each Mailobject In InboxItems
ComputerName = Mailobject.Subject
ErrorState = Mailobject.Body
strDate = GetDate(Mailobject.SentOn)
SenderEmail = Mailobject.SenderEmailAddress
If strDate = DateToday And SenderEmail = "itadmin@email.org" Then
'\\ Syntax is (key, value)
Computers.Add ComputerName, ErrorState
End If
'MsgBox(Mailobject.Subject)
'MsgBox(Mailobject.SenderName)
'MsgBox(Mailobject.To)
'MsgBox(Mailobject.Body)
Next Mailobject
这个网站非常有用,不仅是我提问的地方,也是我找到相关信息而不必麻烦大家的地方。不幸的是,我经常要麻烦你们所有人,但每次你都非常善良和乐于助人。我想感谢你。
答案 0 :(得分:0)
您尝试使用Collection中的Add()方法来指定数组中的元素。要在二维数组中指定元素,您可以使用arr(a,b)= someValue,其中a和b是数值。 - 蒂姆威廉姆斯