|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 gbgbxgb 于 2017-7-3 10:58 编辑
- Private Sub Workbook_Activate()
- Application.OnKey "{F1}", "ThisWorkbook.Macro1"
- End Sub
- Private Sub Workbook_BeforeClose(Cancel As Boolean)
- Application.OnKey "{F1}", ""
- End Sub
-
- Private Sub Workbook_Deactivate()
- Application.OnKey "{F1}", ""
- End Sub
-
- Private Sub Macro1()
- Dim theStr1$, theStr2$, reg As Object, theLenth&
- '
- With ActiveCell
- If .Row > 1 Then
- theStr1 = .Offset(-1)
- If Len(theStr1) > 0 Then
- theStr2 = .Value
- theLenth = Len(theStr2)
- Set reg = CreateObject("VBScript.RegExp")
- reg.Pattern = "^" & theStr2
- If reg.Test(theStr1) Then
- theStr2 = Left(theStr1, theLenth + 1)
- .Value = theStr2
- End If
- End If
- End If
- End With
- Set reg = Nothing
- End Sub
复制代码
|
|