如何在VBA中包含.NET类?
我是VBA新手,现在想为Outlook创建发送JSON消息的代码。它不编译 编译错误:应为语句结尾 或 编译错误:应为= 代码如下:如何在VBA中包含.NET类?,.net,vba,outlook,.net,Vba,Outlook,我是VBA新手,现在想为Outlook创建发送JSON消息的代码。它不编译 编译错误:应为语句结尾 或 编译错误:应为= 代码如下: Imports System.Net Imports System.IO Imports System.Text Public Sub SendMessage(mail As MailItem) Dim uri As New Uri("http://myip:9050/message") Dim req As Net.HttpWebReques
Imports System.Net
Imports System.IO
Imports System.Text
Public Sub SendMessage(mail As MailItem)
Dim uri As New Uri("http://myip:9050/message")
Dim req As Net.HttpWebRequest = Net.WebRequest.Create(uri)
req.Method = "PUT"
req.Accept = "application/json;"
req.ContentType = "application/json; charset=UTF-8"
Dim jsonString As String = "{ ""message"" : """ + mail + """ }"
Dim jsonDataBytes = System.Text.Encoding.UTF8.GetBytes(jsonString)
req.ContentLength = jsonDataBytes.Length
Dim stream As IO.Stream = req.GetRequestStream()
stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
stream.Close()
req.GetResponse()
End Sub
或视觉上:
我怎样才能让它也工作呢?VBA和.Net是不同的世界 在这种情况下,我建议开发一个Outlook加载项(例如,基于VSTO的加载项),您可以在其中使用所有BCL类。请确保快速开始
此外,您可能会发现MSDN中的部分很有帮助 您可以编写.net COM Outlook插件。然后你就可以在了望台上使用它了,谢谢。目前,我正在使用VBA调用PowerShell脚本,如下所示
调用Shell(“PowerShell.exe-ExecutionPolicy Unrestricted-File C:\Scripts\Send-Message.ps1-Message test from outlook”,1)
。COM模块会更好,更易于重用,也许以后会更好。