zoukankan      html  css  js  c++  java
  • 列出一个工作簿中所有已使用的自定义函数

    需要添加对VB项目的信任

    Sub UDFSOFACTIVEWORKBOOK()
    Dim sh As Worksheet, r As Range, dic As Object, i As Long, temp As String, vbcomp, s() As String, UDF As String
    For i = 1 To ActiveWorkbook.VBProject.VBComponents.Count
    Set vbcomp = ActiveWorkbook.VBProject.VBComponents(i)
    If vbcomp.Type = 1 Then temp = temp & vbCrLf & vbcomp.CodeModule.Lines(1, 65536)
    Next
    s = Split(temp, vbCrLf)
    temp = ""
    For i = 0 To UBound(s)
    If s(i) Like "Function * As *" Then temp = temp & "@" & "=" & Trim(Split(Split(s(i), "(")(0), "Function")(1)) & "(" '--->All functions with or without parameters
    Next
    Set dic = CreateObject("scripting.dictionary")
    For Each sh In Sheets
    For Each r In sh.UsedRange
    If r.HasFormula Then
    If InStr(temp, "@" & Split(r.Formula, "(")(0)) > 0 Then
    UDF = r.Formula & "udf"
    Else
    UDF = ""
    End If
    If Not dic.exists(r.Formula) Then dic.Add r.Formula, UDF
    End If
    Next
    Next
    Debug.Print "All functions used in activesheet" & vbCrLf & String(50, "-") & vbCrLf & Join(dic.keys, vbCrLf) & vbCrLf & vbCrLf '列出一个工作簿中所有函数
    Debug.Print "All user define functions used in activesheet" & vbCrLf & String(50, "-") & vbCrLf & Replace(Join(Filter(dic.items, "udf"), vbCrLf), "udf", "") '列出一个工作簿中所有已使用的自定义函数
    Set dic = Nothing
    End Sub 

  • 相关阅读:
    密码
    日历游戏
    最大公约数
    从map到hash
    9、RabbitMQ-集成Spring
    8、RabbitMQ-消息的确认机制(生产者)
    7、RabbitMQ-主题模式
    6、RabbitMQ-路由模式
    5、RabbitMQ-订阅模式 Publish/Subscribe
    4、RabbitMQ-消息应答与消息持久化
  • 原文地址:https://www.cnblogs.com/fengju/p/6336295.html
Copyright © 2011-2022 走看看