1
Const vbDoubleQuote As String = """" 'represents 1 double quote (")
Const vbSingleQuote As String = "'" 'represents 1 single quote (')
Private WithEvents myOlItems  As Outlook.Items

Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")
  Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal item As Object)

Dim Msg As Outlook.MailItem
Dim Title As String
Dim Body As String
Dim Message As String

  Set Msg = item

Title = Msg.Subject
Body = Msg.Body

TargetURL = "https://api.pushbullet.com/v2/pushes"


Set HttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HttpReq.Option(4) = 13056
HttpReq.Open "POST", TargetURL, False
HttpReq.SetCredentials "user", "password", 0

HttpReq.setRequestHeader "Authorization", "Bearer myAPI"
HttpReq.setRequestHeader "Content-Type", "application/json"


Message = "{""channel_tag"": ""myChannel"", ""type"": ""note"",  ""title"": " & _
  vbDoubleQuote & Title & vbDoubleQuote & ", ""body"": " & _
  vbDoubleQuote & Body & vbDoubleQuote & "}"
  HttpReq.Send (Message)

大家好,对不起,如果这个问题对你们来说太简单了,但我对此一无所知。

以上是我的代码,在消息中我将标题放在代码中间阅读我定义的内容:

 (""title"": " & _
  vbDoubleQuote & Title & vbDoubleQuote & ") as "Title = Msg.Subject". 

但是仍然在推送没有任何消息的空消息时,只是一个空消息。

我是否错误地定义了字符串?

4

1 回答 1

0

您需要在续行之间关闭并重新打开您的字符串:

您可能还需要为 vbDoubleQuote 声明一个 Const

Const vbDoubleQuote As String = """"

Message = "{""channel_tag"": ""myChannel"", ""type"": ""note""," & _
    """title"": " & _
    vbDoubleQuote & Title & vbDoubleQuote & ", ""body"": " & _
    vbDoubleQuote & Body & vbDoubleQuote & "}"

{“channel_tag”:“myChannel”,“type”:“note”,“title”:“MYTITLE”,“body”:“MYBODY”}

于 2016-09-23T03:34:03.733 回答