+ Reply to Thread
Results 1 to 12 of 12

sending sms from excel vba

Hybrid View

  1. #1
    Registered User
    Join Date
    10-01-2020
    Location
    cameroun
    MS-Off Ver
    office 2007
    Posts
    37

    sending sms from excel vba

    Hi all.
    You will find attached a vba code for sending sms.
    it runs normally but does not deliver sms.
    Someone to help me figure out what is missing please






    Sub send_SMS_RDV()
    
    
        Application.ScreenUpdating = False
    
            
            
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''''''essai code xfactor'''''''''''''''''''''
                Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
              Dim Recipient As String
               Dim Message As String
               
        Dim rowname As String
        Dim rowprestardv As String
        
        
        Dim rowtimerdv, rownumber, rowdaterdv, x  As String
        
        rowtimerdv = Worksheets("PLANNING").Range("I4").Value
        rowprestardv = Worksheets("PLANNING").Range("H4").Value
        rowname = Worksheets("PLANNING").Range("N4").Value
        rownumber = Worksheets("PLANNING").Range("O4").Value
        rowdaterdv = Worksheets("PLANNING").Range("Q4").Value
        
        
        x = "237"
        Recipient = "x&lastrownumber"
               
    
    '
        If rowdaterdv = Worksheets("PLANNING").Range("P32").Value Then
    '
            Message = "Dear  " & rowname & ",  your appointment has  been register at : " & rowtimerdv & " Contact us for any changes. Merci"
               Else
    '
            Message = "Dear  " & rowname & ",  your appointment has  been register at : " & rowdaterdv & " Contact us for any changes. Merci"""
    
    '
    ' 
            End If
               
               
                'Set vars where phone numbers and msg are set in your sheet'
    
                URL = api.smsfactor.com/send?text=" + Message + "&to=" + Recipient
                objHTTP.Open "GET", URL, False
                objHTTP.SetRequestHeader "Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIzNDcwOSIsImlhdCI6MTYwMTk5NzM4N30.VbWdRwVwtIn5JtwNYjeJ8imnM_2bYskRIg2O6uZG5fA" 'Your Token'
                objHTTP.SetRequestHeader "Accept", "application/json"
                objHTTP.send ("")
            
            
            
          End Sub

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,991

    Re: sending sms from excel vba

    What are you trying to do with this line of code:

        Recipient = "x&lastrownumber"
    It is setting Recipient to the string "x&lastrownumber" which is probably not a valid recipient string. Is it supposed to getting a phone number from a cell? At first I thought you meant this:

        Recipient = x & lastrownumber
    but there is no variable lastrownumber. Could you possibly mean this?

        Recipient = x & rownumber

  3. #3
    Registered User
    Join Date
    10-01-2020
    Location
    cameroun
    MS-Off Ver
    office 2007
    Posts
    37

    Re: sending sms from excel vba

    Thank for your reply

    I retrieve the telephone number in the "lastrownumber" cell then concatenate it with the code of my country "x"

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,991

    Re: sending sms from excel vba

    Also I don't believe this runs because this line does not compile:

                URL = api.smsfactor.com/send?text=" + Message + "&to=" + Recipient
    Do you mean this?

                URL = "api.smsfactor.com/send?text=" & Message & "&to=" & Recipient

  5. #5
    Registered User
    Join Date
    10-01-2020
    Location
    cameroun
    MS-Off Ver
    office 2007
    Posts
    37

    Re: sending sms from excel vba

    you're right, it's rownumber.
    I corrected and replaced the + by & in the API but it is doesn't work

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,991

    Re: sending sms from excel vba

    The message has embedded spaces. This is not legal in a URL.

    Message = "Dear  " & rowname & ",  your appointment has  been register at : " & rowtimerdv & " Contact us for any changes. Merci"
    Spaces must be converted to %20 in a URL. Do this after the URL is complete:

                URL = Replace(URL, " ", "%20")
    I am still getting automation error with your code, still trying to figure out what else is wrong.

  7. #7
    Registered User
    Join Date
    10-01-2020
    Location
    cameroun
    MS-Off Ver
    office 2007
    Posts
    37

    Re: sending sms from excel vba

    OK, thanks.
    I'm also looking on my side.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,344

    Re: sending sms from excel vba

    Using these changes I was able to send sms-message.
         x = "+237"
        Recipient = x & lastrownumber
       If rowdaterdv = Worksheets("PLANNING").Range("P32").Value Then
    '
            Message = Replace("Dear  " & rowname & ",  your appointment has  been register at : " & rowtimerdv & " Contact us for any changes. Merci", Chr(32), "+")
               Else
    '
            Message = Replace("Dear  " & rowname & ",  your appointment has  been register at : " & rowdaterdv & " Contact us for any changes. Merci", Chr(32), "+")
    
    '
    '
            End If
    URL = "https://api.smsfactor.com/send?text=" + Message + "&to=" + Recipient
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  9. #9
    Registered User
    Join Date
    10-01-2020
    Location
    cameroun
    MS-Off Ver
    office 2007
    Posts
    37

    Re: sending sms from excel vba

    Thank you for your contribution. I was able to send the messages as well. Really, thank you.

    However, without asking too much, I have another provider that offers me more benefit. So, I would like to replace the previous url with this one.

    app.techsoft-web-agency.com/sms/api?action=send-sms&api_key=Um9kcnlnMTIzOnNhbG9tZQ==&to=PhoneNumber&from=SenderID&sms=YourMessage&unicode=1[/url]

    Please what should I modify for its configuration

  10. #10
    Registered User
    Join Date
    10-01-2020
    Location
    cameroun
    MS-Off Ver
    office 2007
    Posts
    37

    Re: sending sms from excel vba

    I have to cut the first part of the url because I am not allowed to post the links

  11. #11
    Registered User
    Join Date
    10-01-2020
    Location
    cameroun
    MS-Off Ver
    office 2007
    Posts
    37

    Re: sending sms from excel vba

    This is how I configured the new url according to the documentation I found on their site.
    But at the line "objWinHTTP.Open" GET ", URL & Request, False" I am told that the url uses an unrecognized protocol




    Sub send_SMS_Fact()
    
        Application.ScreenUpdating = False
    '   Declaring varibles for sending sms
    
        Dim objWinHTTP  As Object
        Dim response, send As String
        Dim sURL As String
        Dim API As String
        Dim SenderID As String
        Dim Recipient, Message As String
    '   Declaring varibles for Application
        Dim rowname As String
        Dim rowtypevente As String
        
        
        Dim rowamount, rownumber, x  As String
        Worksheets("FACTURATION").Activate
        
        rowtypevente = Worksheets("FACTURATION").Range("H11").Text
        rowamount = Worksheets("FACTURATION").Range("M11").Text
        rowname = Worksheets("FACTURATION").Range("S11").Text
        rownumber = Worksheets("FACTURATION").Range("T11").Text
        
        
        API = "Um9kcnlnMTIzOnNhbG9tZQ=="
        x = "237"
        Recipient = x & rownumber
        SenderID = "TechSoft-SMS"
    '   Preparation sms
    
        If rowtypevente = "VENTE DIFF" Then
            
            Message = "Dear  " & rowname & ",  The amount of your invoice which is: " & rowamount & " remains to be paid as soon as possible"
                Else
                rowtypevente = "VENTE"
    
    
            Message = "Dear  " & rowname & ",  We thank you for your loyalty and hope to have satisfied you. Best regards and see you soon"
        
        End If
    '  Checking for valid mobile number
    
        If rownumber <> "700000000" Then
    
            
     
    
        Else
            Recipient = CStr(rownumber)
    
     
        End If
    
    
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''test protocole url'''''
        Set objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    
        sURL = app.techsoft-web-agency.com/sms/api"
        sURL = Replace(sURL, " ", "%20")
        Request = "&apikey=" & API & URLEncode(Apikey) & "&number=" & Recipient & URLEncode(Number)
        Request = Request & "&message=" & Message & URLEncode(Message)
        Request = Request & "&expediteur=" & SenderID & URLEncode(Expediteur) & "&msg_id=" & MsgID
    
        objWinHTTP.Open "GET", URL & Request, False
        objWinHTTP.SetTimeouts 30000, 30000, 30000, 30000
        objWinHTTP.send
        If objWinHTTP.StatusText = "OK" Then
            strReturn = objWinHTTP.ResponseText
            Debug.Print strReturn
        End If
    
        Set objWinHTTP = Nothing
        send = strReturn
    
    
    
    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Public Function URLEncode(sRawURL) As String
        On Error GoTo Catch
        Dim iLoop As Integer
        Dim sRtn As String
        Dim sTmp As String
        Const sValidChars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz:/.?=_-$()~&"
        If Len(sRawURL) > 0 Then
            For iLoop = 1 To Len(sRawURL)
                sTmp = Mid(sRawURL, iLoop, 1)
                If InStr(1, sValidChars, sTmp, vbBinaryCompare) = 0 Then
                    sTmp = Hex(Asc(sTmp))
                    If sTmp = "20" Then
                        sTmp = "+"
                    ElseIf Len(sTmp) = 1 Then
                        sTmp = "%0" & sTmp
                    Else
                        sTmp = "%" & sTmp
                    End If
                End If
                sRtn = sRtn & sTmp
            Next iLoop
            URLEncode = sRtn
        End If
    Finally:
            Exit Function
    Catch:
            URLEncode = ""
            Resume Finally
    End Function

  12. #12
    Registered User
    Join Date
    03-25-2021
    Location
    USA
    MS-Off Ver
    2016
    Posts
    8

    Re: sending sms from excel vba

    Thanks Experts!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. sending sms from excel vba
    By rodryg123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2020, 06:33 AM
  2. Replies: 1
    Last Post: 01-08-2016, 09:57 AM
  3. Copying content of one excel to another excel and sending email with excel data
    By archies.gall in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2012, 02:22 PM
  4. Something out of the Purview of Excel-Sending Excel table as a body in an Email?
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2011, 07:50 AM
  5. [SOLVED] Sending SMS from Excel
    By Piotr in forum Excel General
    Replies: 1
    Last Post: 11-03-2005, 06:00 AM
  6. Sending fax from Excel
    By Bogdan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-14-2005, 11:05 AM
  7. Replies: 0
    Last Post: 04-02-2005, 09:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1