2016-09-23 58 views
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". 

但仍然在推什麼,但空消息沒有任何消息,只是一個空的消息。

我錯誤地定義了字符串嗎?

+0

在'HttpReq.Send'行之前添加'Debug.Print Message'並在直接窗口中查看它。它看起來正確嗎? – Comintern

+0

嗨@Comintern,感謝您的幫助,在添加該行後,郵件根本沒有推送到我的PushBullet。 我注意到,當我在「Set Msg = item」後面定義一些東西時 代碼停止推送.. – Sap1

回答

0

您需要關閉並重新打開線延續之間的字符串:

您可能還需要聲明一個const爲vbDoubleQuote

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「}

+0

hmm,@ComIntern編輯了這個問題,這個答案可能不再適用? – ThunderFrame

+0

它看起來像OP試圖在我的複製和粘貼的標記中添加強行換行符。這可能或可能不準確。 – Comintern

+0

嗨@ThunderFrame,感謝您的幫助,但是在您的代碼工作時定義消息。我正試圖調用我在消息中稱呼的函數。 改爲「MYTITLE」,我需要它讀取「Msg.Subject」,它是來自「Outlook.MailItem」的屬性,它將讀取電子郵件主題。 感謝您的幫助:) – Sap1

相關問題