ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: Emily

FAQ 工作薄及工作表 (Update 8 Aug 2005)

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-7-4 12:28 | 显示全部楼层

列出所有工作薄的 VBA

本帖已被收录到知识树中,索引项:工作表和工作簿

列出所有工作薄的 VBA

由 Mr Colo写的 VBA 需要在VBA内选取 Microfost Visual Basic Applications Extensbility

请在 Tools - 宏 - 安全性 - 选取 信任存取 Visual Basic 项目

' Module
' List All VBA module
Dim x As Long
Dim aList()

Sub GetVbProj()
    Dim oVBC As VBIDE.VBComponent
    Dim Wb As Workbook
    x = 2
    For Each Wb In Workbooks
        For Each oVBC In Workbooks(Wb.Name).VBProject.VBComponents
            If Workbooks(Wb.Name).VBProject.Protection = vbext_pp_none Then
                Call GetCodeRoutines(Wb.Name, oVBC.Name)
            End If
        Next
    Next
    With Sheets.Add
        .[A1].Resize(, 3).Value = Array("Workbook", "Module", "Procedure")
        .[A2].Resize(UBound(aList, 2), UBound(aList, 1)).Value = _
        Application.Transpose(aList)
        .Columns("A:C").Columns.AutoFit
    End With
End Sub

Private Sub GetCodeRoutines(wbk As String, VBComp As String)
    Dim VBCodeMod As CodeModule
    Dim StartLine As Long

    On Error Resume Next
    Set VBCodeMod = Workbooks(wbk).VBProject.VBComponents(VBComp).CodeModule
    With VBCodeMod
        StartLine = .CountOfDeclarationLines + 1
        Do Until StartLine >= .CountOfLines
            ReDim Preserve aList(1 To 3, 1 To x - 1)
            aList(1, x - 1) = wbk
            aList(2, x - 1) = VBComp
            aList(3, x - 1) = .ProcOfLine(StartLine, vbext_pk_Proc)
            x = x + 1
            StartLine = StartLine + .ProcCountLines(.ProcOfLine(StartLine, _
                                            vbext_pk_Proc), vbext_pk_Proc)
            If Err Then Exit Sub
        Loop
    End With
    Set VBCodeMod = Nothing
End Sub

[此贴子已经被作者于2006-9-27 15:38:33编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-7-10 12:34 | 显示全部楼层

不可以选择或编辑单元格

不可以选择或编辑单元格

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim Myrange As Range, KeepOut As Range
    Dim ws As Worksheet
    
    'Full sheet
    'Set KeepOut = ActiveSheet.Cells
    'Several Columns
    'Set KeepOut = ActiveSheet.Range("B:D")
    'Test Range
    Set KeepOut = ActiveSheet.Range("A2:C5")
        
    Set Myrange = Intersect(Target, KeepOut)
    'Leave if the intersecttion ws untouched
    If Myrange Is Nothing Then Exit Sub

    'Stop select firing a second time
    Application.EnableEvents = False
    If KeepOut.Rows.Count = 65536 And KeepOut.Columns.Count = 256 Then
        'Entire sheet is the KeepOut range. Eek!
        'Bounce user to a dummy sheet
        On Error Resume Next
        Set ws = ThisWorkbook.Sheets("KickMeTo")
        On Error GoTo 0
        If ws Is Nothing Then
            Set ws = ThisWorkbook.Sheets.Add
            ws.Name = "KickMeTo"
        End If
        MsgBox "Houston we have a problem" & vbNewLine & _
               "You cannot select any cell in " & vbNewLine & "'" & KeepOut.Parent.Name & "'" & vbNewLine & _
               "So you have been directed to a different sheet"
        ws.Activate
    ElseIf KeepOut.Rows.Count = 65536 Then
        'If all rows are contained in the "KeepOut" range then:
        'Now we need to find a cell that is in a column to the right or left of this range
        If KeepOut.Cells(1).Column > 1 Then
            'If there is a valid column to the left of the range then select the cell in this column
            Cells(KeepOut.Cells(1).Row, KeepOut.Cells(1).Column - 1).Select
        Else
            'Else select the cell in first column to the right of the range
            Cells(KeepOut.Cells(1).Row, KeepOut.Cells(1).Column + 1).Select
        End If
          MsgBox "You cannot select " & KeepOut.Address(False, False) & vbNewLine & _
          "You have been directed to the first free column in the protected range", vbCritical
    ElseIf KeepOut.Rows.Count + KeepOut.Cells(1).Row - 1 = 65536 Then
        'Select first cell in Column A before "KeepOut" Range
        Cells(KeepOut.Cells(1).Row - 1, 1).Select
          MsgBox "You cannot select " & KeepOut.Address(False, False) & vbNewLine & _
          "You have been directed to the first free cell in Column A above the protected range", vbCritical
    Else
        'Select first cell in Column A beyond "KeepOut" Range
    MsgBox "You cannot select " & KeepOut.Address(False, False) & vbNewLine & _
          "You have been directed to the first free cell in Column A below the protected range", vbCritical
        Cells(KeepOut.Rows.Count + KeepOut.Cells(1).Row, 1).Select
    End If
    Application.EnableEvents = True
End Sub

[此贴子已经被作者于2006-9-27 15:38:58编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-8-8 12:03 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

vba 程式碼(代碼)是否限定容量不得超過 64K 限制嗎

MicroSoft 沒有文件顯示 編碼 的大小限制
64K 太大,很難跟進

以下編碼檢示 Module 的大小

Sub get_Mod_Size()
Dim myProject As Object
Dim ComName As String
Dim tempPath As String
Dim fs As Object, a As Object
Dim result As String

' **************************************************************************************
' Use this to determine the size of a module
' Set ModName (component name) and tempPath (where to store the temp fule), then run
' **************************************************************************************

' Set these to run
ComName = "Module1"
tempPath = "c:\Test.bas"

' ***** No action needed after this point *****

' Export the component (module, form, etc) - this is only temporary
Set myProject = Application.VBE.ActiveVBProject.VBComponents
myProject(ComName).Export (tempPath)

' Get the size of the file created
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.getfile(tempPath)
result = ComName & " uses " & (a.Size / 1000) & " KB."

' Return the file size
MsgBox result, vbExclamation

' Delete the exported file
fs.Deletefile tempPath

End Sub

[此贴子已经被作者于2006-9-27 15:39:14编辑过]

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2005-9-20 20:23 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2005-10-7 21:32 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2005-10-7 21:56 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
以下是引用mkb在2005-10-7 21:32:00的发言: 全部都是精品中的精品

是嗎

可惜再沒有了 !!!

TA的精华主题

TA的得分主题

发表于 2005-11-2 01:07 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

好贴、好贴。感谢Emily,让我学会了不少知识。

顶一下,不能让他沉了。

TA的精华主题

TA的得分主题

发表于 2005-11-14 02:54 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2005-12-15 14:00 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2006-2-4 20:03 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-12-24 09:37 , Processed in 0.042489 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表