你们都很有帮助,我想知道我是否可以再麻烦你们一点。我几乎完成了从 VB.net 到 VBA for Outlook 的转换,为了完成它,我需要一些关于特定代码返回的确切信息的信息。如果你们都可以帮助解决这个问题,问题可能会消失;如果没有,我可能需要一些帮助来解决这个无效的限定符错误。
据我了解,我在 VBA 中使用如下命令声明了一个“数组”:
Dim Computers(1, 1) As String
这会产生一个 2x2 数组。然后我尝试像这样填充它:
Computers.Add ComputerName, ErrorState
其中 ComputerName 和 ErrorState 是我已经填写的变量。这会导致错误。我将在下面为您提供整个相关部分。我需要知道 Outlook 收件箱中有多少相关项目,这意味着检查它们是否是在今天的日期以及由正确的发件人发送的。我需要这个才能在阵列计算机上获得正确的尺寸。(该数组现在已填充,因为我知道正确的尺寸,但实际上我不会。)我通过谷歌找到了一段代码,脚本字典输出,但我并不完全理解它。我只需要电子邮件的数量,没有任何不相关的文本,我希望调试行能够告诉我需要哪个命令来返回数字而不是其他任何东西。不幸的是,由于上述错误,我无法到达这条线。即使通过单步执行代码,它告诉我的第一件事就是这里存在问题。整个相关部分如下。我知道格式有问题,但我只使用 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
这个网站非常有帮助,它不仅是我提问的地方,也是我查找相关信息而不必麻烦大家的地方。不幸的是,我经常不得不麻烦你们,但每次你们都非常友善和乐于助人。我要感谢你。