1.文檔保存為啟用宏的工作簿
2.然后打開工作i簿乞巧,ALT+F11組合鍵打開VBA編輯窗口涨椒,點擊 菜單欄--插入--模塊,復制代碼到新建模塊的代碼編輯區(qū)
3.保存,返回工作表蚕冬,和使用其他函數一樣免猾,輸入:=sfind(N23)
Option Explicit
Function sfind(ByVal str As Variant)
Dim mc As Variant
With CreateObject("vbscript.regexp")
.Global = False
.Pattern = "[0-9]{6}"
If Not .test(str) Then
sfind = "null": Exit Function
End If
Set mc = .Execute(str)
End With
sfind = mc.Item(0)
Set mc = Nothing
End Function"
參考鏈接:https://zhidao.baidu.com/question/1950611345817243908.html