想用VBA列出内置函数

时间:2017-01-27 16:49:10

标签: excel vba excel-vba access-vba access

我想以编程方式使用VBA生成Access文件中可用的VBA函数列表(文本,表格,无关紧要)。我不打算生成用户编写的函数列表。 。 。我希望生成一个内置函数列表。我希望生成一个列表,如下所示:

left,instr,date,mid,asc,reverse,month,cstr等等。

我看一下VBA对象浏览器,在转换,日期时间,文件系统,财务,信息,交互,数学和字符串的类名下有VBA命令的完整集合。

我已尝试在VBA中尝试枚举这些类的所有类型的对象声明,但尚未成功。我想要做的就是枚举函数名。

2 个答案:

答案 0 :(得分:4)

当前版本的Rubberduck(2.0.12,尚未发布 - 计划于2月初发布)使COM API再次运行(2.0.11打破了它),因此如果您可以构建当前版本(& #34; next" branch,使用Visual Studio)...或者等待2.0.12,你可以引用Rubberduck的类型库并编写如下的VBA代码:

Option Explicit

Public Sub ListAllLoadedDeclarations()
    Dim ducky As Rubberduck.ParserState
    Set ducky = New Rubberduck.ParserState
    ducky.Initialize Application.VBE
    ducky.Parse

    Dim item As Variant
    Dim typedItem As Rubberduck.Declaration

    For Each item In ducky.AllDeclarations
        Set typedItem = item
        If typedItem.DeclarationType = DeclarationType_Function _
            Or typedItem.DeclarationType = DeclarationType_Procedure _
            Or typedItem.DeclarationType = DeclarationType_PropertyGet _
            Or typedItem.DeclarationType = DeclarationType_PropertyLet _
            Or typedItem.DeclarationType = DeclarationType_PropertySet _
        Then
            ' Project.Module.Member
            Debug.Print typedItem.ParentDeclaration.ParentDeclaration.Name & "." & _
                        typedItem.ParentDeclaration.Name & "." & _
                        typedItem.Name & " (" & DeclarationTypeName(typedItem.DeclarationType) & ")"
        End If
    Next

End Sub

Private Function DeclarationTypeName(ByVal value As Rubberduck.DeclarationType) As String
    Select Case value
        Case DeclarationType_Function
            DeclarationTypeName = "Function"
        Case DeclarationType_Procedure
            DeclarationTypeName = "Sub"
        Case DeclarationType_PropertyGet
            DeclarationTypeName = "Property Get"
        Case DeclarationType_PropertyLet
            DeclarationTypeName = "Property Let"
        Case DeclarationType_PropertySet
            DeclarationTypeName = "Property Set"
    End Select
End Function

这将列出所有早期绑定引用中的所有SubFunctionProperty成员(包括VBE中的所有"用户代码"),打印它们到立即窗格(您可能希望更改Debug.Print以写入文件),看起来像这样(在Excel项目中):

(snip)
Excel.PivotTable.Name (Property Let)
Excel.PivotTable.ViewCalculatedMembers (Property Get)
Excel.PivotTable.SourceData (Property Get)
Excel.PivotTable.InGridDropZones (Property Get)
Excel.PivotTable.GrandTotalName (Property Get)
Excel.PivotTable.Update (Sub)
Excel.PivotTable.SmallGrid (Property Get)
Excel.PivotTable.EnableWriteback (Property Get)
Excel.PivotTable.Version (Property Get)
Excel.PivotTable.ShowCellBackgroundFromOLAP (Property Get)
Excel.PivotTable.RowRange (Property Get)
Excel.PivotTable.CalculatedFields (Function)
Excel.PivotTable.AllocateChanges (Sub)
Excel.PivotTable.AllocationValue (Property Get)
Excel.PivotTable.DisplayMemberPropertyTooltips (Property Let)
Excel.PivotTable.CacheIndex (Property Let)
Excel.PivotTable.CompactRowIndent (Property Get)
Excel.PivotTable.DiscardChanges (Sub)
Excel.PivotTable.EnableDrilldown (Property Get)
Excel.PivotTable.AlternativeText (Property Get)
Excel.PivotTable.DataLabelRange (Property Get)
Excel.PivotTable.ListFormulas (Sub)
Excel.PivotTable.AllowMultipleFilters (Property Let)
Excel.PivotTable.RowAxisLayout (Sub)
Excel.PivotTable.ShowTableStyleColumnHeaders (Property Get)
Excel.PivotTable.Tag (Property Get)
Excel.PivotTable.LayoutRowDefault (Property Get)
Excel.PivotTable.DataPivotField (Property Get)
Excel.PivotTable.TableStyle (Property Get)
Excel.PivotTable.DisplayNullString (Property Get)
Excel.PivotTable.PageRange (Property Get)
Excel.PivotTable.CalculatedMembersInFilters (Property Get)
Excel.PivotTable.ShowPageMultipleItemLabel (Property Get)
Excel.PivotTable.Summary (Property Let)
Excel.PivotTable.DisplayFieldCaptions (Property Let)
Excel.PivotTable.ChangePivotCache (Sub)
Excel.PivotTable.ShowTableStyleRowStripes (Property Let)
Excel.PivotTable.EnableWizard (Property Let)
Excel.PivotTable.PageFields (Property Get)
Excel.PivotTable.PageFieldOrder (Property Get)
Excel.PivotTable.PrintTitles (Property Let)
Excel.PivotTable.SubtotalHiddenPageItems (Property Get)
Excel.PivotTable.VisualTotalsForSets (Property Let)
Excel.PivotTable.ShowTableStyleRowHeaders (Property Let)
Excel.PivotTable.PivotSelectionStandard (Property Get)
Excel.PivotTable.AddFields (Function)
Excel.PivotTable.CompactLayoutRowHeader (Property Get)
Excel.PivotTable.RepeatItemsOnEachPrintedPage (Property Get)
Excel.PivotTable.AllocationMethod (Property Let)
Excel.PivotTable.VacatedStyle (Property Get)
Excel.PivotTable.Value (Property Get)
Excel.PivotTable.GetPivotData (Function)
Excel.PivotTable.InnerDetail (Property Let)
Excel.PivotTable.Format (Sub)
Excel.PivotTable.PageFieldStyle (Property Get)
Excel.PivotTable.SubtotalLocation (Sub)
Excel.PivotTable.ShowPages (Function)
Excel.PivotTable.ShowValuesRow (Property Let)
Excel.PivotTable.MDX (Property Get)
Excel.PivotTable.DataBodyRange (Property Get)
Excel.PivotTable.PreserveFormatting (Property Get)
Excel.PivotTable.DisplayContextTooltips (Property Let)
Excel.PivotTable.ChangeList (Property Get)
Excel.PivotTable.Location (Property Let)
Excel.PivotTable.PivotSelection (Property Let)
Excel.PivotTable.RefreshDate (Property Get)
Excel.PivotTable.VisibleFields (Property Get)
Excel.PivotTable.MergeLabels (Property Get)
Excel.PivotTable.EnableDataValueEditing (Property Let)
Excel.PivotTable.TableRange1 (Property Get)
Excel.PivotTable.ShowDrillIndicators (Property Get)
Excel.PivotTable.Allocation (Property Get)
Excel.PivotTable.Parent (Property Get)
Excel.PivotTable.DisplayImmediateItems (Property Let)
Excel.PivotTable.HasAutoFormat (Property Get)
Excel.PivotTable.PageFieldWrapCount (Property Get)
Excel.PivotTable.EnableFieldDialog (Property Let)
Excel.PivotTable.RepeatAllLabels (Sub)
Excel.PivotTable.VisualTotals (Property Get)
Excel.PivotTable.DisplayEmptyColumn (Property Get)
Excel.PivotTable.CubeFields (Property Get)
Excel.PivotTable.ShowTableStyleLastColumn (Property Get)
Excel.PivotTable.PivotTableWizard (Sub)
Excel.PivotTable.PageRangeCells (Property Get)
Excel.PivotTable.DisplayErrorString (Property Let)
Excel.PivotTable.RowGrand (Property Let)
Excel.PivotTable.SortUsingCustomLists (Property Get)
Excel.PivotTable._Default (Property Let)
Excel.PivotTable.ColumnGrand (Property Let)
Excel.PivotTable.CalculatedMembers (Property Get)
Excel.PivotTable.Application (Property Get)
Excel.PivotTable.ShowTableStyleColumnStripes (Property Get)
Excel.PivotTable.PivotColumnAxis (Property Get)
Excel.PivotTable.NullString (Property Get)
Excel.PivotTable.Slicers (Property Get)
Excel.PivotTable.ErrorString (Property Let)
Excel.PivotTable.AllocationWeightExpression (Property Get)
Excel.PivotTable.DisplayEmptyRow (Property Get)
Excel.PivotTable.SaveData (Property Get)
Excel.PivotTable.EnableFieldList (Property Get)
Excel.PivotTable.SelectionMode (Property Let)
Excel.PivotTable.FieldListSortAscending (Property Get)
Excel.PivotTable.RefreshDataSourceValues (Sub)
Excel.PivotTable.ViewCalculatedMembers (Property Let)
Excel.PivotTable.SourceData (Property Let)
Excel.PivotTable.TableStyle2 (Property Get)
Excel.PivotTable.CommitChanges (Sub)
Excel.PivotTable.InGridDropZones (Property Let)
Excel.PivotTable.GrandTotalName (Property Let)
Excel.PivotTable.TotalsAnnotation (Property Get)
Excel.PivotTable.CompactLayoutColumnHeader (Property Get)
Excel.PivotTable.PrintDrillIndicators (Property Get)
Excel.PivotTable.SmallGrid (Property Let)
Excel.PivotTable.EnableWriteback (Property Let)
Excel.PivotTable.ManualUpdate (Property Get)
Excel.PivotTable.Name (Property Get)
Excel.PivotTable.ShowCellBackgroundFromOLAP (Property Let)
Excel.IFont.TintAndShade (Property Let)
Excel.IFont.Creator (Property Get)
Excel.IFont.ThemeColor (Property Get)
Excel.IFont.Size (Property Get)
Excel.IFont.Italic (Property Get)
Excel.IFont.Strikethrough (Property Get)
Excel.IFont.FontStyle (Property Get)
Excel.IFont.Parent (Property Get)
Excel.IFont.Color (Property Get)
Excel.IFont.Name (Property Get)
Excel.IFont.OutlineFont (Property Get)
Excel.IFont.Application (Property Get)
Excel.IFont.Underline (Property Get)
Excel.IFont.ThemeColor (Property Let)
Excel.IFont.Size (Property Let)
Excel.IFont.Italic (Property Let)
Excel.IFont.Strikethrough (Property Let)
Excel.IFont.FontStyle (Property Let)
Excel.IFont.ThemeFont (Property Get)
Excel.IFont.Color (Property Let)
Excel.IFont.Name (Property Let)
Excel.IFont.OutlineFont (Property Let)
Excel.IFont.Underline (Property Let)
Excel.IFont.Shadow (Property Get)
Excel.IFont.ThemeFont (Property Let)
Excel.IFont.Superscript (Property Get)
Excel.IFont.Subscript (Property Get)
Excel.IFont.ColorIndex (Property Get)
Excel.IFont.Shadow (Property Let)
Excel.IFont.Superscript (Property Let)
Excel.IFont.Subscript (Property Let)
Excel.IFont.Bold (Property Get)
Excel.IFont.ColorIndex (Property Let)
Excel.IFont.Background (Property Get)
Excel.IFont.Bold (Property Let)
Excel.IFont.TintAndShade (Property Get)
Excel.IFont.Background (Property Let)
Rubberduck._Extension.OnBeginShutdown (Sub)
Rubberduck._Extension.OnConnection (Sub)
Rubberduck._Extension.OnStartupComplete (Sub)
Rubberduck._Extension.ToString (Property Get)
Rubberduck._Extension.OnAddInsUpdate (Sub)
Rubberduck._Extension.GetHashCode (Function)
Rubberduck._Extension.OnDisconnection (Sub)
Rubberduck._Extension.GetType (Function)
Rubberduck._Extension.Equals (Function)
Excel.IPivotLines.Application (Property Get)
Excel.IPivotLines.Parent (Property Get)
Excel.IPivotLines.Creator (Property Get)
Excel.IPivotLines.Item (Property Get)
Excel.IPivotLines.Count (Property Get)
Excel.IPivotLines._NewEnum (Property Get)
Excel.IPivotLines._Default (Property Get)
Office.ICTPFactory.CreateCTP (Function)
Office.IRibbonControl.Tag (Property Get)
Office.IRibbonControl.Context (Property Get)
Office.IRibbonControl.Id (Property Get)
Office.FoundFiles.Application (Property Get)
Office.FoundFiles.Count (Property Get)
Office.FoundFiles.Creator (Property Get)
Office.FoundFiles._NewEnum (Property Get)
Office.FoundFiles.Item (Property Get)
Office.PickerDialog.Creator (Property Get)
Office.PickerDialog.CreatePickerResults (Function)
Office.PickerDialog.Resolve (Function)
Office.PickerDialog.Title (Property Let)
Office.PickerDialog.Show (Function)
Office.PickerDialog.Title (Property Get)
Office.PickerDialog.DataHandlerId (Property Let)
Office.PickerDialog.Properties (Property Get)
Office.PickerDialog.Application (Property Get)
Office.PickerDialog.DataHandlerId (Property Get)
Excel.Menu.Enabled (Property Let)
Excel.Menu.MenuItems (Property Get)
Excel.Menu.Enabled (Property Get)
Excel.Menu.Delete (Sub)
Excel.Menu.Parent (Property Get)
Excel.Menu.Caption (Property Let)
Excel.Menu.Index (Property Get)
Excel.Menu.Caption (Property Get)
Excel.Menu.Creator (Property Get)
Excel.Menu.Application (Property Get)

请注意,这包括隐藏成员,Rubberduck也知道返回类型,参数和可见性,但API目前使得有效查询事物变得有点困难。

Rubberduck的COM API仍然是一个实验性功能,需要进行重大更改,并且对建议和功能请求非常开放,因此我不建议在任何生产代码中使用它 - 但是使用它当然可以通过抓取MSDN或编写自己的COM类型库读取器/反射器,可以更快地到达某个地方。

由于我们将此信息序列化为XML,以便我们的测试和网站尝试代码检查"功能可以在VBE之外工作,您也可以尝试反序列化我们的XML files,并获取所有这些信息。

  

完全披露:我参与了Rubberduck的开发。

答案 1 :(得分:2)

您可以从this page左侧的列表中检索列表。