Sunday, July 29, 2012

Texting from Excel

I have figured out how to send a text from Excel. It is really sending a POST request to my website using VBA and passing the phone number and message from 2 cells in the spreadsheet. Put the phone number in A2 and the message in B2. Then press Alt F11 to open the VBA code editor. Under Microsoft Excel Object on the left pane open the current spreadsheet. Or you could add the code to a new module by right clicking on Modules and choosing insert module. Next put this code in it.
Private Sub GetWebRequestButton1_Click()
    'get the numbers to send to the website to get a response
    Number = Sheets("texting").Range("A2").Value
    Message = Sheets("texting").Range("B2").Value
    
    'This sends a post to the website and put the response in the range supplied
    With ActiveSheet.QueryTables.Add(Connection:="URL;http://yourwebsite.com/VBAtexting.php", Destination:=Range("C2"))
        .PostText = "sendtext=1&number=" & Number & "&message=" & Message
        .RefreshStyle = xlOverwriteCells
        .SaveData = True
        .Refresh
    End With
End Sub
It works great.
You will also need the code for texting using google voice on your website but it is pretty simple and I use it all the time to send automated texts.