how to keep the first cell always active in excel using vba

我们两清 提交于 2019-12-02 16:09:29

问题


How to keep the first cell always active when opening the excel sheet.

Can any one guide me to how to this.

This is my code:

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

       End Sub

回答1:


I'm not quite sure why you would want the first cell to be active. If it's just because you are using ActiveCell in your Code then you should be defining a Range instead. Like this:

Private Sub Send_Click()
   Dim strURL As String
   strURL = "http://xxxxxxxxxxxx.com/excelAPI.php?customer_id=1&mobilenumber=" _
   & Range("A1").Value & "&message=" & Range("A1").Offset(0, 1).Value
   Call Sheets("Sheet1").WebBrowser4.Navigate(strURL)
End Sub

Anyway. This is how you activate the first cell (A1) of YourWorksheet when the Workbook is opened:

Private Sub Workbook_Open() 
   Worksheets("YourWorksheet").Activate
   Range("A1").Activate
End Sub


来源:https://stackoverflow.com/questions/16382801/how-to-keep-the-first-cell-always-active-in-excel-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!