1

This is my code

Private Sub Send_Click()
Dim cell As Range, Rng As Range
Dim strURL As String

Set Rng = Selection

For Each cell In Rng
    strURL = "http://xxxxxxxx.com/excelAPI.php?customer_id=1&mobilenumber=" _
           & cell.Value & "&message=" & cell.Offset(0, 1).Value
    Call Sheets("Sheet1").WebBrowser4.Navigate(strURL)
Next cell

Set Rng = Nothing

End Sub          

i am Highlighted only 3 mobile number in cell A and i click the button it takes only the last number.

5
  • WebBrowser4- what is it? how do you defined it or where from you have this instruction? Commented May 1, 2013 at 6:37
  • i got it from Web Browser Control in Microsoft Excel 2007 VBA Commented May 1, 2013 at 6:53
  • when button clicked i want to pass active cell value to mobile number in url.please can you guide me i m new to vba Commented May 1, 2013 at 6:54
  • When you say selecting 3 mobile numbers in cell A1 are they all in cell A1 or in A1, A2, A3? And you are selecting all three cells? Commented May 1, 2013 at 8:15
  • Sorry, without seeing the actual file I don't know why it would not work, everything seems to be okay. Are you able to post the file somehow; dropbox etc? FYI, I will be offline for a few hours so will look back when i can. Commented May 1, 2013 at 8:23

1 Answer 1

2

Probably easiest to build the string first:

Dim strURL as String
strURL = "http://xxxxxxx.com/excelAPI.php?customer_id=1&mobilenumber=" _
   & ActiveCell.Value & "&message=" & ActiveCell.Offset(0,1).Value
Call Sheets("Sheet1").WebBrowser4.Navigate(strURL)

Assuming the active cell contains the mobile number and the cell to it's immediate right contains the required message, otherwise specify the cells:

Dim strURL as String
strURL = "http://xxxxxxx.com/excelAPI.php?customer_id=1&mobilenumber=" _
   & Range("A1").Value & "&message=" & Range("B1").Value
Call Sheets("Sheet1").WebBrowser4.Navigate(strURL)

You may need to qualify your range worksheets.

EDIT As requested in comments to cycle through selected cells:

Dim cell As Range, Rng As Range
Dim strURL as String

Set Rng = Selection

For Each cell In Rng
    strURL = "http://xxxxxxx.com/excelAPI.php?customer_id=1&mobilenumber=" _
       & cell.Value & "&message=" & cell.Offset(0,1).Value
    Call Sheets("Sheet1").WebBrowser4.Navigate(strURL)
Next cell

Set Rng = Nothing

Only select the cells that contain the mobile numbers, otherwise the code will try to send to the messages as well. You may want to write in some check to ensure the cell contains a number such as:

If IsNumeric(cell.Value) Then

Or a more detailed format check depending on what you have in the columns of the worksheet.

Sign up to request clarification or add additional context in comments.

11 Comments

Thanks also i want to pass the another active cell value to message can to you tell how can i do that
regarding to range Al and B1 each time i want to change range i dont want to change .if select any range of cell it automatically dectet the range of the cell and pass that to url ,is this possible
The first example will pick up the mobile number from whatever is the active cell at the time the code is run and then pick up and use whatever is in the cell next to it to the right (offset(0,1)) and use it as the message.
but i want to send highlighted numbers in excel how can do that
What do you mean by highlighted? You want to search through a series of cells and send if the cell is highlighted?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.