如何在VBA中发送Pushover

如何在VBA中发送Pushover,vba,excel,pushover,Vba,Excel,Pushover,通过VBA发送邮件的最佳方法是什么? 在Pushover网站中,我没有找到VBA示例 他就是这个函数 PS:我使用辅助函数格式化字符串 测试功能: Public Sub Test() Debug.Print PushOverPost("myApplication", "mySubscriptionGroup", "Hello Stackoverflow!") End Sub ' Send a post via PushOver ' @param In applica

通过VBA发送邮件的最佳方法是什么? 在Pushover网站中,我没有找到VBA示例

他就是这个函数

PS:我使用辅助函数格式化字符串

测试功能:

  Public Sub Test()
      Debug.Print PushOverPost("myApplication", "mySubscriptionGroup", "Hello Stackoverflow!")
  End Sub
  ' Send a post via PushOver
  ' @param In application as String: The application's token
  ' @param In group as String: The user/group token
  ' @param In message as String: The message that you want to send
  ' @return as String(): The post response
  Public Function PushOverPost(ByVal application As String, ByVal group As String, ByVal message As String) As String
      Dim xhttp As Object, params As String, url As String
      Set xhttp = CreateObject("MSXML2.ServerXMLHTTP")

      params = StringFormat("token={0}&user={1}&message={2}", application, group, message)
      url = "https://api.pushover.net/1/messages.json"

      With xhttp
          .Open "POST", url, False
          .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
          .send params

          PushOverPost = .responseText
      End With
  End Function
  ' Generate a string using .NET format, i.e. {0}, {1}, {2} ...
  ' @param In strValue as String: A composite format string that includes one or more format items
  ' @param In arrParames as Variant: Zero or more objects to format.
  ' @return as String: A copy of format in which the format items have been replaced by the string representations of the corresponding arguments.
  ' @example: Debug.Print StringFormat("My name is {0} {1}. Hey!", "Mauricio", "Arieira")
  Public Function StringFormat(ByVal strValue As String, ParamArray arrParames() As Variant) As String
      Dim i As Integer

      For i = LBound(arrParames()) To UBound(arrParames())
          strValue = Replace(strValue, "{" & CStr(i) & "}", CStr(arrParames(i)))
      Next

      StringFormat = strValue
  End Function
推覆功能:

  Public Sub Test()
      Debug.Print PushOverPost("myApplication", "mySubscriptionGroup", "Hello Stackoverflow!")
  End Sub
  ' Send a post via PushOver
  ' @param In application as String: The application's token
  ' @param In group as String: The user/group token
  ' @param In message as String: The message that you want to send
  ' @return as String(): The post response
  Public Function PushOverPost(ByVal application As String, ByVal group As String, ByVal message As String) As String
      Dim xhttp As Object, params As String, url As String
      Set xhttp = CreateObject("MSXML2.ServerXMLHTTP")

      params = StringFormat("token={0}&user={1}&message={2}", application, group, message)
      url = "https://api.pushover.net/1/messages.json"

      With xhttp
          .Open "POST", url, False
          .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
          .send params

          PushOverPost = .responseText
      End With
  End Function
  ' Generate a string using .NET format, i.e. {0}, {1}, {2} ...
  ' @param In strValue as String: A composite format string that includes one or more format items
  ' @param In arrParames as Variant: Zero or more objects to format.
  ' @return as String: A copy of format in which the format items have been replaced by the string representations of the corresponding arguments.
  ' @example: Debug.Print StringFormat("My name is {0} {1}. Hey!", "Mauricio", "Arieira")
  Public Function StringFormat(ByVal strValue As String, ParamArray arrParames() As Variant) As String
      Dim i As Integer

      For i = LBound(arrParames()) To UBound(arrParames())
          strValue = Replace(strValue, "{" & CStr(i) & "}", CStr(arrParames(i)))
      Next

      StringFormat = strValue
  End Function
辅助功能:

  Public Sub Test()
      Debug.Print PushOverPost("myApplication", "mySubscriptionGroup", "Hello Stackoverflow!")
  End Sub
  ' Send a post via PushOver
  ' @param In application as String: The application's token
  ' @param In group as String: The user/group token
  ' @param In message as String: The message that you want to send
  ' @return as String(): The post response
  Public Function PushOverPost(ByVal application As String, ByVal group As String, ByVal message As String) As String
      Dim xhttp As Object, params As String, url As String
      Set xhttp = CreateObject("MSXML2.ServerXMLHTTP")

      params = StringFormat("token={0}&user={1}&message={2}", application, group, message)
      url = "https://api.pushover.net/1/messages.json"

      With xhttp
          .Open "POST", url, False
          .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
          .send params

          PushOverPost = .responseText
      End With
  End Function
  ' Generate a string using .NET format, i.e. {0}, {1}, {2} ...
  ' @param In strValue as String: A composite format string that includes one or more format items
  ' @param In arrParames as Variant: Zero or more objects to format.
  ' @return as String: A copy of format in which the format items have been replaced by the string representations of the corresponding arguments.
  ' @example: Debug.Print StringFormat("My name is {0} {1}. Hey!", "Mauricio", "Arieira")
  Public Function StringFormat(ByVal strValue As String, ParamArray arrParames() As Variant) As String
      Dim i As Integer

      For i = LBound(arrParames()) To UBound(arrParames())
          strValue = Replace(strValue, "{" & CStr(i) & "}", CStr(arrParames(i)))
      Next

      StringFormat = strValue
  End Function