|
各位大神
我想实现这样的目的:
附件的Excel中目前有2个工作表,sheet1和sheet2。
sheet2中写入了代码,只要双击A1单元格即可返回sheet1.[A1],想这个工作簿中其他新增的工作表都会自动在工作表的界面写入跟sheet2一样的过程,这样每次双击本工作表的A1即可返回sheet1.[A1]
学习了类似代码,但是不能实现目的,请大神指导下,谢谢。
代码如下
- 'sheet2代码
- Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
- If Target.Address(False, False) = "A1" Then Sheet1.Activate: Sheet1.[A1].Select
- End Sub
复制代码- 'thisworkbook里的代码
- Private Sub Workbook_NewSheet(ByVal Sh As Object)
- With ActiveWorkbook.VBProject.VBComponents(Sh.CodeName).CodeModule
- .InsertLines 1, "Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)"
- .InsertLines 2, "If Target.Address(False, False) = ""A1"" Then Sheet1.Activate: Sheet1.[A1].Select"
- .InsertLines 3, "End Sub"
- End With
- End Sub
复制代码
|
|