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.

4

1 回答 1

2

首先构建字符串可能最容易:

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)

假设活动单元格包含手机号码,并且其直接右侧的单元格包含所需的消息,否则指定单元格:

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)

您可能需要限定您的范围工作表。

编辑 根据评论中的要求循环选择单元格:

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

只选择包含手机号码的单元格,否则代码也会尝试发送到消息中。您可能需要写一些检查以确保单元格包含一个数字,例如:

If IsNumeric(cell.Value) Then

或者根据您在工作表列中的内容进行更详细的格式检查。

于 2013-05-01T06:59:54.247 回答