我在VB.NET中写作非常新,我甚至没有意识到VB.NET和VBA之间存在显着差异.我一直在Visual Studio中编写我的应用程序,但我意识到我需要将它移植到Outlook中的VBA,并且我需要处理一些语法问题.我已经搜索过,但是我找不到VBA甚至VB6的任何明确的引用(比如msdn),从我听到的内容比VB.NET更接近VBA.
我将在此处包含相关的代码部分.如果有人需要更多的背景,请让我知道 - 我可以发布整个事情,它不是那么久.不过,我想让这篇文章尽可能简单.
Dim DateToday As String = String.Format("0:{yyyy/MM/dd}", DateTime.Now)
Dim Computers As New SortedList()
Dim disabledList As New List(Of String)
'\\ four additional lists
Dim compArray As Array
...
Computers.Add(ComputerName, ErrorState)
Run Code Online (Sandbox Code Playgroud)
新列表和排序列表在List之后的括号中给出Expected:Statement of Statement.该数组在Array中给出Expected:identifier.字符串DateToday在等号处给出了预期的语句结束.添加到排序列表的尝试给出了Expected:=.
我一直在使用VB.NET大概两三天,之前我从未使用过VBA或VB6,所以我只是没有必要的经验知道从哪里开始.如果你们中的任何一个愿意帮助我,我会非常感激!
I have a piece of vb.net code that I wrote. It's a for loop with two embedded if statements, and the compiler is telling me that each elseif and endif must be preceded by a matching if.
This is my second day of working with vb.net ever, and the only programming experience I have is writing .bat files, so this could be something really stupid. But I cannot figure out why I'm getting these errors, and if you all would …
我正在尝试使用此页面上的功能:http://www.outlookcode.com/d/code/getfolder.htm使用文件夹路径导航到文件夹.(我会把这个代码复制到这个问题的底部 - 我原样使用它,完全没有修改.)我需要使用它的原因是Outlook中的默认收件箱与我需要的收件箱不同积极点.通过右键单击并点击属性并查看位置,我知道相关收件箱的路径.
这是我使用的代码:
Set objOutlook = CreateObject("Outlook.Application", "localhost")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set Inbox = GetFolder("\\itadmin@email.org\inbox")
Debug.Print Inbox '<-- This fails
Set InboxItems = Inbox.Items '<-- This also fails
InboxItems.SetColumns ("SentOn")
Run Code Online (Sandbox Code Playgroud)
这将返回运行时错误91,对象变量或未设置块变量.
我不知道这是什么意思.如果你可以帮我解决这个错误,那就太棒了,如果你有办法让我完全避免这个问题,那也很棒.谢谢!
Public Function GetFolder(strFolderPath As String)As MAPIFolder
' strFolderPath needs to be something like
' "Public Folders\All Public Folders\Company\Sales" or
' "Personal Folders\Inbox\My Folder"
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim arrFolders() As …Run Code Online (Sandbox Code Playgroud) 编辑:新信息:我刚才意识到,虽然Mailitem.Body的返回是"",但实际值是"应用程序定义的或对象定义的错误".我不完全确定这意味着什么,但我确实知道它出现在多个领域 - 我在下面放了一个屏幕截图.

我遇到的问题是某些属性会返回正确的值,而其他属性则不会.我有一个示例电子邮件,其中我有一个主题为"主题"的电子邮件,邮件为"正文",发件人电子邮件地址为"email@address.com",发送日期为2013年6月12日.
当我运行以下代码时:
Dim ComputerName As String
Dim ErrorState As String
For Each MailItem In InboxItems
ComputerName = MailItem.Subject
'ErrorState = MailItem.Body
ErrorState = MailBody(MailItem)
strDate = GetDate(MailItem.SentOn)
SenderEmail = MailItem.SenderEmailAddress
If strDate = DateToday And SenderEmail = "email@address.com" Then
Computers(a, 0) = ComputerName
Computers(a, 1) = ErrorState
a = a + 1
End If
Debug.Print MailItem.Subject
Debug.Print MailItem.Body
Next MailItem
Run Code Online (Sandbox Code Playgroud)
我得到的是ComputerName ="Subject",ErrorState ="",SenderEmail =""和strDate ="2013/6/12"(在这种情况下这是正确的格式).为什么这会返回两个Mailitem属性的正确值,而不是其他两个属性?这是一个非常奇怪的问题,我将非常感谢你们所能给予的任何帮助!
我将在这里为代码添加更多上下文:
Set objOutlook = CreateObject("Outlook.Application", "localhost")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set Inbox …Run Code Online (Sandbox Code Playgroud) 谢谢你的时间!对于每个用户,我希望输出一个包含最早生效日期和最新结束日期的列,以及此表和其他表中的其他列(这些内容对每个用户都是一致的).以下是输入数据的格式.
User Eff_Date End_Date Otherstuff...
----|-------------|------------|---------
001 | 20140101 | 20140106
001 | 20140107 | 99990101
002 | 20140201 | 20140305
002 | 20140306 | 20140319
002 | 20140320 | 99990101
003 | 20140401 | 20140402
004 | 20140501 | 20250901
Run Code Online (Sandbox Code Playgroud)
这基本上是我所希望的结果:
User Eff_Date End_Date Otherstuff...
----|-------------|------------|---------
001 | 20140101 | 99990101
002 | 20140201 | 99990101
003 | 20140401 | 20140402
004 | 20140501 | 20250901
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
SELECT DISTINCT M.user, T.mineffdate, T.maxenddate, A.otherstuff
FROM tbluser M
LEFT JOIN otherstuff …Run Code Online (Sandbox Code Playgroud) vba ×3
outlook ×2
sortedlist ×2
vb.net ×2
arrays ×1
date ×1
if-statement ×1
list ×1
mailitem ×1
mapi ×1
max ×1
min ×1
sql ×1
sql-server ×1