Outlook VBA中的String.Add无效限定符 [英] Invalid Qualifier for String.Add in Outlook VBA

查看:165
本文介绍了Outlook VBA中的String.Add无效限定符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家都很乐于助人,我想知道是否还会给您带来更多麻烦.我几乎完成了从VB.net到Outlook的VBA转换,并且要完成此转换,我需要一些有关特定代码返回的确切信息.如果大家都可以帮忙,问题可能会消失.如果没有,我可能需要一些有关此无效限定符错误的帮助.

You all have been so helpful, and I was wondering whether I might trouble you a bit more. I have nearly completed my conversion from VB.net to VBA for Outlook, and in order to complete that, I need some information on what exactly a particular piece of code is returning. If you all can help out with that, the problem may go away; if not, I might need some help on this invalid qualifier error.

据我了解,我在VBA中用如下命令声明了一个数组":

From what I understand, I declare an 'array' in VBA with a command like this:

Dim Computers(1, 1) As String

产生2x2数组.然后,我尝试像这样填充它:

Which produces a 2x2 array. I then try to fill it like this:

Computers.Add ComputerName, ErrorState

其中ComputerName和ErrorState是我已经填写的变量.这导致错误.我将在下面为您提供整个相关部分.我需要知道Outlook收件箱中有多少个相关项目,这意味着检查它们是否是在今天的日期以及由正确的发件人发送的.我需要这样做,以便在阵列计算机上获得正确的尺寸. (由于我知道正确的尺寸,数组现在已填满,但实际上我不会.)我采用了一段代码,这些代码是我通过google找到的脚本字典输出,但是我并不完全理解.我只需要电子邮件的数量,没有任何不相关的文本,我希望调试行能够告诉我我需要返回哪个命令,而别无其他.不幸的是,由于上述错误,我无法到达这一行.即使单步执行代码,它告诉我的第一件事就是这里存在问题.整个相关部分如下.我知道格式有问题,但是我只使用VB.NET已有4天的时间,而这是我使用VBA的第二天,所以我还没有完全放弃.我敢肯定,这里有一些无关紧要的内容,但是我没有经验来询问某些内容是否相关,因此我将所有内容都保留了下来.抱歉,长度不够!

where ComputerName and ErrorState are variables which I have already filled. This results in the error. I will provide you with the entire relevant section below. I need to know how many relevant items are in the outlook inbox, which means checking if they were sent on today's date and by the correct sender. I need this in order to get the correct dimensions on the array Computers. (The array is filled in right now as I know the correct dimensions, but in practise I will not.) I took a piece of code which I found through google, the Scripting Dictionary output, but I do not fully understand it. I need just the number of emails, without any irrelevant text, and I was hoping that the debug line would be able to tell me which command I would need to return the number and nothing else. Unfortunately, because of the above error, I cannot get to this line. Even by stepping through the code, the very first thing it tells me is that there is a problem here. The entire relevant section is below. I know that the formatting is problematic, but I have only been working with VB.NET for 4 days, and this is my second day of working with VBA, so I do not quite have everything down yet. There's some irrelevant stuff in here, I'm pretty sure, but I do not have the experience to make the call of whether something is relevant or not, so I left it all. Sorry for the length!

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 

这个网站不仅对我提出问题提供了极大的帮助,而且对于我来说也可以找到相关信息而又不会给大家带来麻烦.不幸的是,我常常不得不麻烦你们所有人,但是每次您都非常友善和乐于助人.我要感谢你.

This website has been incredibly helpful as not only a place for me to ask questions but also as a place for me to find relevant information without having to trouble you all. Unfortunately, it is all too often that I do have to trouble you all, but every time you have been very kind and helpful. And I would like to thank you for that.

推荐答案

您正尝试使用Collection中的Add()方法在数组中分配元素.要在二维数组中分配元素,可以使用arr(a,b)= someValue,其中a和b是数字值. –蒂姆·威廉姆斯

you're trying to use the Add() method from a Collection to assign an element in an array. To assign an element in a 2-D array you'd use arr(a,b)=someValue where a and b are numeric values. – Tim Williams

没有答案的问题,但是发出了在评论中解决了

这篇关于Outlook VBA中的String.Add无效限定符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆