![](/img/trans.png)
[英]How to get the cell count matching the value and color of the active from CountIF, and loop code equal to cell count found from CountIF in VBA Excel?
[英]how to pass the active cell value to the URL in vba excel 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
我在单元格A中仅突出显示了3个移动电话号码,然后单击按钮,它仅接收最后一个电话号码。
首先构建字符串可能最简单:
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
或更详细的格式检查,具体取决于工作表各列中的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.