Tip Bitcoins as an incentive.
Earn Bitcoins for being helpful.


Provide me a script to send free sms with excel vba


Please sign in to answer this question.


4 Answers

  • Domipa
  • 15:08 23.02.2020

Installing SMSLibX
Download and install SMSLibX on your PC.
(Optional) Download and install our Excel SMS examples (sending/receiving SMS from VBA source code).
Connect and install your GSM modem or phone to your PC.
If you don't have a compatible GSM modem/phone, then you can use SMSLibX in simulation mode.


Integrating SMSLibX into Excel
Open an existent Excel worksheet or create a new one.
Switch to the VBA source code (Tools > Macro > Visual Basic Editor), then select your worksheet in the Project tree.
Set up a reference to SMSLibX library (Tools > References menu).
If you can't find SMSLibX into the list, please search it with the Browse button.
Now you're ready to use SMSLibX objects and methods directly in your source code.



Sending and receiving SMS from Excel (VBA)
The following VBA source code might be used into an Excel worksheet module, in order to send and receive SMS messages. With few modifications this code can be inserted in a VBA class module too.

The WithEvents clause is essential in order to catch events raised by the SMSModem object.

' Declare SMSModem object
Public WithEvents Modem As SMSModem


' Send SMS
Private Sub cmdSendMessage_Click()

' Open modem communication
Set Modem = New SMSModem
Modem.LogTrace = True
Modem.OpenComm ModemType, ModemPort, , smsNotifyAll

' Send message
Call Modem.SendTextMessage(PhoneNumber, MessageText)


End Sub


' Receive SMS by event
Private Sub Modem_MessageReceived(Message As SMSLibX.SMSDeliver)
MsgBox "New message received from " & Message.Originator & ":" _
& vbCrLf & vbCrLf & Message.Body, _
vbInformation, "New message received"
End Sub
''
------------
Using SMSLibX in your VBA editor
For a brief introduction on SMSLibX usage we recommend the Quick start section from SMSLibX Help.

SMSLibX is fully integrated into the Microsoft VBA development environment:

To display contextual help on a selected SMSLibX item, just click F1.
To browse SMSLibX library items, please open the Object Viewer (F2) and select SMSLibX library.
You can use code completion when writing code using SMSLibX objects (Ctrl+SPACE, Ctrl+J etc.)


Two examples: Excel worksheets sending/receiving SMS
The following Excel worksheets provided with VBA source code are available for download:

Example1
Minimal example sending and receiving SMS.

Example2
Medium-complexity example sending and receiving multiple SMS.

Both examples are pre-configured for simulation mode (they do not send real SMS).

Once you got them working on yoir PC, you can configure them in order to use your actual GSM modem/phone by opening the worksheet source code (Tools > Macro > Visual Basic Editor menu) and modifying the 'TO DO' items.

If you experience some troubles, please refer to the "Troubleshooting" section.



SMSLibX events and VB6 programming
Please read these notes carefully – they are very important for a good SMSLibX programming practice!



MsgBox and received SMS messages
If your VBA application makes use of MsgBox and InputBox, please note that VBA suppresses events from timers, forms, controls and ActiveX components while one of these dialogs is open.
Events are not simply delayed but definitively suppressed (please see Microsoft Knowledge Base 76557 article).

Due to this disagreeable behaviour, if a MsgBox is open your application may loose events notifying received messages - and any other event generated by SMSLibX.

As work-around, we suggest redefining the VBA MsgBox function and replacing it with the MessageBox API from Windows (which does not suppress events: please see Microsoft Knowledge Base 76557 article for details).
A concrete MsgBox re-definition example is available in the example source code
distributed with this tutorial.



Yielding control in your loops
If your VBA application cycles over a list of SMS messages to be sent - or performs some other time-consuming operations - then you should provide a DoEvents statement in your loop (or time-consuming operaton).

This will permit SMSLibX to continue raising its events in real-time (such as received messages, delivery reports and modem status events).

Moreover, your SMSLibX event listeners (the code you write inside an event procedure) should never contain time-consuming operations, since SMSLibX relies on the event calling thread for further message capture and notification.

  • BugsBunny
  • 04:58 25.02.2020

If sending bulk SMS via API. I'd generally recommend using something other than VBA. Since, VBA in itself is limited to single thread. Though you can get around this using external process/library, but it isn't ideal. I'd recommend using .NET, java or python. Utilizing async request processing.

But check with your vendor, the limit on number of recipients in single request. If it's large enough, you can use VBA to build string and send request via xmlhttp using their http api

Sub send_SMS(xyz As Integer)

Application.ScreenUpdating = False
' Declaring varibles for sending sms

Dim HttpReq As New WinHttpRequest
Dim response As String
Dim sURL As String
Dim smsto, smstext As String
' Declaring varibles for Application

Dim lastrow, lastrow1, lastrow2, x, pointe As Long
lastrow = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
lastrow1 = Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
lastrow2 = Sheets(3).Range("A" & Rows.Count).End(xlUp).Row

' Caculation of red card points

If xyz = 1 Then
pointe = (frmmain.txtpointe.Value - frmmain.txtpointr.Value) + (frmmain.txtamount.Value * 10 / 100)
smstext = "Dear Member, You have reedemed " & frmmain.txtpointr.Text & " red points and your balance is " & pointe & " points"
Else
pointe = frmmain.txtpointe.Value + (frmmain.txtamount.Value * 10 / 100)
If pointe >= 1000 Then

smstext = "Dear Member, You have reached " & pointe & " red points and you can reedem it your next visit"
Else

smstext = "Dear Member, Your bill amount is " & frmmain.txtinvoice.Text & " and your Red Point balance is " & pointe & " Points"
End If
End If
' Checking for valid mobile number

If Len(frmmain.lblmobile.Caption) < 10 Then


Call nomobile(pointe)

Else
smsto = CStr(frmmain.lblmobile.Caption)

' //another way to create the HttpReq
Set HttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")

' // API for sending sms
sURL = "https://malert.in/api/api_http.php?username=username&password=password&senderid=REDHCP&to=" & smsto & "&text=" & smstext & "&route=Enterprise&type=text"
' Debug.Print sURL
On Error Resume Next

With HttpReq
.Open "GET", sURL, False
.send
End With

response = HttpReq.responseText
HttpReq.waitForResponse
' MsgBox Left(response, 2)
Debug.Print response

If Left(response, 2) = "OK" Then
Call nomobile(pointe)
Else
Call errorconnection(smstext, pointe)
End If
End If
sURL = "https://malert.in/api/api_http_balance.php?username=username&password=password&route=Enterprise"
' Debug.Print sURL
On Error Resume Next

With HttpReq
.Open "GET", sURL, False
.send
End With

response = HttpReq.responseText
HttpReq.waitForResponse
frmmain.lblstatus.Caption = response
Debug.Print response
Application.ScreenUpdating = True
End Sub

  • bahar98
  • 05:48 26.03.2020

Hi

Sure.

I have created a account on " http://www.smsidea.biz/ "
They infact have an option to download the excel plugin.

  • mzade
  • 23:37 05.04.2020

thanks you working sms receive


- or -
- or -