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.

Community
  • 1
  • 1
arok
  • 107
  • 2
  • 5
  • 13
  • `WebBrowser4`- what is it? how do you defined it or where from you have this instruction? – Kazimierz Jawor May 01 '13 at 06:37
  • i got it from Web Browser Control in Microsoft Excel 2007 VBA – arok May 01 '13 at 06: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 – arok May 01 '13 at 06: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? – Simon1979 May 01 '13 at 08: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. – Simon1979 May 01 '13 at 08:23

1 Answers1

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.

Simon1979
  • 2,110
  • 1
  • 12
  • 15
  • Thanks also i want to pass the another active cell value to message can to you tell how can i do that – arok May 01 '13 at 07:06
  • 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 – arok May 01 '13 at 07:08
  • 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. – Simon1979 May 01 '13 at 07:10
  • but i want to send highlighted numbers in excel how can do that – arok May 01 '13 at 07:18
  • What do you mean by highlighted? You want to search through a series of cells and send if the cell is highlighted? – Simon1979 May 01 '13 at 07:19
  • for example if i have 10 cells and I select all of them, So I want to perform the function to all of them. Thanks – arok May 01 '13 at 07:20
  • Not sure why, I test it and it works okay for me. Are you selecting just the cells that contain the mobile number? In what way is it not working? – Simon1979 May 01 '13 at 07:42
  • yes.i replace the c with a in the code .is this ok can you write me the full code if dont mind with cell A(number) and B(message) – arok May 01 '13 at 07:49
  • if you Dim a As Range then you must then change all uses of c to a. What is the benefit of this though? c is a reference to the cell, it is not the column C, I have changed the answer to reflect this. – Simon1979 May 01 '13 at 07:51
  • i m selecting just the cells that contain the mobile number it taking only the last number – arok May 01 '13 at 07:56
  • Edit your question and put in the code you have and tell me the cells you are selecting before you run the code. – Simon1979 May 01 '13 at 08:00