Send SMS via VoipBuster using VBA - vba

I am total beginner, but I am trying to make a macro in VBA to send an SMS using VoipBuster platform when a condition is completed.
Is it possible? Is it easier to use the application installed on PC or web page (https://www.voipbuster.com/sms).
Please help!

For send sms from voipbuster you can send it by php vars...
"https://www.voipbuster.com/myaccount/sendsms.php?username=$USER&password=$PASS&from=$FROM&to=\"$TO\"&text=$SMS_TEXT"
So you need to access iexplore from vba like this , create you vars use, pass, text etcc and concat everythins like the URL before ..
to call iexplore from VBA you will find a lot of ways with google , here you got an example
Private Sub IE_Autiomation()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = False
' Send the form data To URL As POST binary request
IE.Navigate "https://www.voipbuster.com/myaccount/sendsms.php?username=$USER&password=$PASS&from=$FROM&to=\"$TO\"&text=$SMS_TEXT"

Try below code. You can also test by putting the value in URL variable to your browser.
Sub SendSms()
Dim username As String
Dim password As String
Dim sendTo As String
Dim msg As String
username = "test" 'enter username here
password = "test" 'enter password here
sendTo = "9999999999"
msg = "Hello"
Dim URL As String
URL = "https://www.voipbuster.com/myaccount/sendsms.php?username=" & username & "&password=" & password & "&to=" & sendTo & "&text=" & msg
Dim xml As Object
Set xml = CreateObject("MSXML2.XMLHTTP")
xml.Open "GET", URL, False
xml.send
End Sub

Related

how to invoke api url in outlook userform

I have created userform and try to input parameters and invoke the api url to “create incident”
api url:https://***.com/incident/create
to create an incident http post a json payload to the url above,example as below
{
“state”:“**”
“caller_id”:“**”
.
.
.
“urgency”=“**”
}
outlook userfrom has been created for inputting parameters just to match the json,so how could user invoke the api url in the userform to “create incident” in the userform ui?
Here is an example which shows how you can use web calls from VBA (not only from user forms):
Sub listPokemons()
Dim json As String
Dim jsonObject As Object, item As Object
Dim i As Long
Dim ws As Worksheet
Dim objHTTP As Object
'We selected our results sheet
Set ws = Worksheets("results")
'We create our request object and send
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "https://pokeapi.co/api/v2/pokemon"
objHTTP.Open "GET", URL, False
objHTTP.Send
strResult = objHTTP.responseText
json = strResult
Set objectJson = JsonConverter.ParseJson(json)
'We create the header cells
ws.Cells(1, 1) = "name"
ws.Cells(1, 2) = "link"
'We loop the results property of the API response
i = 2 'We will start the counter on line 2
For Each pokemon InJsonObject("results")
ws.Cells(i, 1) = pokemon("name")
ws.Cells(i, 2) = pokemon("url")
i = i + 1
next
End Sub
It is possible to perform all types of requests - GET, POST, UPDATE.
Read more about that in the How to use Excel VBA to query REST JSON APIs article.

vba Open URL in Chrome including login and password

I want to open a url in chrome and supply the login ID and password.
My current code for IE looks like the below. From other posts I see Chrome can be opened via a basic shell command. Is there a way to pass the login id and password as part of the shell command? If no, what should the code look like to accomplish this? Thanks in advance!
Public Sub WeltokLogin()
'REFERENCES: MS Internet Controls, and MS HTML Object Library (No longer working in Windows 10)
On Error Resume Next
Const URL$ = "https://.../human.aspx"
Exit Sub
Dim UserName As String, Password As String
Dim htmlEle As IHTMLElement
Dim i As Integer
i = 1
UserName = "myloginID"
Password = "mypassword"
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
Dim AllLinks As Object
Dim Hyperlink As Object
With IE
.navigate URL
ieBusy IE
.Visible = True
Dim oLogin As Object, oPassword As Object
Set oLogin = .document.getElementsByName("Username")(0)
Set oPassword = .document.getElementsByName("Password")(0)
oLogin.Value = UserName
oPassword.Value = Password
.document.forms(0).submit
'Loop Until ie.ReadyState = 4
Exit Sub
Set AllLinks = IE.document.getElementsByTagName("div")(0)
For Each Hyperlink In AllLinks
If InStr(1, Hyperlink.innerText, "Folders") > 0 Then
Hyperlink.Click
Exit For
End If
Next Hyperlink
Stop

Get data back from XML

Goodday everybody,
For my thesis I'm developing a model in excel which calculates the distance and traveltime of trucks from the depot to the customer. With this model we can create a good basic understanding of the transport.
I still struggle with getting information back from an XML file and to put this in excel. I have made the following script in VBA.
Public Function G_Distance(startGPS As String, eindGPS As String) As Variant
'vervoer As String'
Dim vehicletype As String
Dim Apikey As String
Dim linkAPIkey As String
Dim linkstartGPS As String
Dim linkendGPS As String
Apikey = "&api_key=ee0b8233adff52ce9fd6afc2a2859a28"
linkstartGPS = "&start=" & startGPS
linkendGPS = "&end=" & eindGPS
vehicletype = "&"
''' Link put location to KM'''
Language = "&lang=en"
Maxresponseamount = "&MaxResponse=1"
Distanceunits = "&distunit=KM"
Dim IE As New InternetExplorer
IE.Visible = True
IE.navigate "http://openls.geog.uni-heidelberg.de/route?
&routepref=HeavyVehicle" & linkstartGPS & linkendGPS & Language &
Maxresponseamount & Distanceunits & Apikey
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
Set doc = IE.document
Dim sDD As String
sDD = Trim(doc.getElementsByTagName("xls:TotalDistance value").innerText)
G_Distance = sDD
End Function
So what this script does is that you put the GPS location of the departure and the GPS location of the destination into 2 different cells (A2 and B2). To start the function you use: =G_distance(A2;B2)
When you start this function it will open up an explorer and here you will see the XML file with the distance in it. Now the only part that doesn't work is to get the data out of the XML into excel.
I hope you guys can help me with this.
Greetings,
Jelle

Adding the default signature to Outlook email

I have an application that will fill out the To/Subject/Body of an outlook email:
Dim App As New Outlook.Application
Dim MailItem As Outlook._MailItem = DirectCast(App.CreateItem(Outlook.OlItemType.olMailItem), Outlook._MailItem)
Dim appDataDir As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Microsoft\Signatures"
Dim Signature As String = String.Empty
Dim diInfo As New DirectoryInfo(appDataDir)
If diInfo.Exists Then
Dim fiSignature As FileInfo() = diInfo.GetFiles("*.htm")
If fiSignature.Length > 0 Then
Dim sr As New StreamReader(fiSignature(0).FullName, Encoding.[Default])
Signature = sr.ReadToEnd()
If Not String.IsNullOrEmpty(Signature) Then
Dim fileName As String = fiSignature(0).Name.Replace(fiSignature(0).Extension, String.Empty)
Signature = Signature.Replace(fileName & Convert.ToString("_files/"), (Convert.ToString(appDataDir & Convert.ToString("/")) & fileName) + "_files/")
End If
End If
End If
With MailItem
.To = "asdf"
.Subject = "asdf"
.Body = txtTemplatePreview.Text & vbNewLine
End With
MailItem.Display(True)
So the function of the first If Then statement is to append my default signature to the end of the email. However, when this code is run, the signature that is appended looks to be HTML code instead of the signature itself.
In addition, I'm told that the first If Then statement will fail if the user has more than one signature. Is there a way to circumvent this?
Work with HTMLBody Property
The property Returns or sets a String representing the HTML body of the specified item. The HTMLBody property should be an HTML syntax string. Read/write.
There is no need to do any of that - the signature is added automatically when Display is called if you do not set the Body or HTMLBody property before that.

Copying from Internet Explorer text area (box) but into more than a single cell

I'm currently trying to control/automate a postcode looking website from postcodes stored and updated in Excel, and my code works perfectly up to the point it has to copy the data once it's finished. For the life of me I can't figure out how to copy the data from the text box / area into Excel without it just putting it ALL into one cell (Text to Columns doesn't really work either).
The website is : http://www.doogal.co.uk/DrivingDistances.php
Sub Geo2()
Dim sht As Worksheet
Dim IE As Object
'Dim ieDoc As HTMLDocument
Dim Item As Variant
Dim objElement As Object
Dim startLoc As String
Dim endLoc As String
Dim x As Integer
Dim objNotes As Object
Dim strNotes As String
Dim str As String
'Dim SignInButton As HTMLInputButtonElement
Set sht = ThisWorkbook.Sheets("Postcode")
Set IE = CreateObject("InternetExplorer.Application")
'Open IE
IE.Visible = True
IE.Navigate "http://www.doogal.co.uk/DrivingDistances.php"
'Wait until site is loaded
Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
DoEvents
Loop
IE.Document.getElementbyID("startLocs").Value = "dn1 5pq" 'random postcode
IE.Document.getElementbyID("endLocs").Value = "wf12 2fd" 'random postcode
IE.Document.getElementsByName("calculateFor").Item(1).Checked = True
IE.Document.getElementsByName("units").Item(1).Checked = True
IE.Document.getElementsByClassName("btn btn-primary").Item(0).Click
------
'Ive tried without having it as a object and using .value but it either comes with only the first line or the entire thing rammed into a string and is unusable
----Code here is the problem-----
***Set objNotes = IE.Document.getElementbyID("distances")
str = objNotes.Value***
---------
Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
DoEvents
Loop
End Sub
The following VBA function uses the Google Maps Directions API to calculate the driving distance in meters between two locations. The code is modified from a version submitted by barrowc on this similar question.
Make sure to add a reference in Excel to Microsoft XML, v6.0.
Function getDistance(origin As String, destination As String) As String
Dim xhrRequest As XMLHTTP60
Dim domDoc As DOMDocument60
Dim ixnlDistanceNode As IXMLDOMNode
Dim RequestString As String
Dim API_Key As String
' Insert your own Google Maps Directions API key here
API_Key = "XXXXXX"
' Read the data from the website
Set xhrRequest = New XMLHTTP60
RequestString = "https://maps.googleapis.com/maps/api/directions/xml?origin=" _
& origin & "&destination=" & destination & "&sensor=false&key=" & API_Key
xhrRequest.Open "GET", RequestString, False
xhrRequest.send
' Copy the results into a format we can manipulate with XPath
Set domDoc = New DOMDocument60
domDoc.LoadXML xhrRequest.responseText
' Select the node called value underneath the leg and distance parents.
' The distance returned is the driving distance in meters.
Set ixnlDistanceNode = domDoc.SelectSingleNode("//leg/distance/value")
getDistance = ixnlDistanceNode.Text
Set ixnlDistanceNode = Nothing
Set domDoc = Nothing
Set xhrRequest = Nothing
End Function
Please note that this code by itself violates the Terms of Use of Google's API. "The Google Maps Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited."1
Instead of putting the data all in one string, Split the string into an array, then loop through the array like this:
Set objNotes = IE.Document.getElementbyID("distances")
Dim x as Integer
Dim aDist() as Variant
aDist = Split(objNotes.Value, vbNewLine) 'May need to be vbCr or vbLf or vbCrLf
For x = 0 to Ubound(aDist) - 1
debug.print aDist(x)
Next x