VBA/Excel/Access/Word/Application/VBE

Материал из VB Эксперт
Версия от 12:46, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Clear Immediate window through VBE

 
     Sub ImmediateWindowClear()
           Application.VBE.Windows.Item("Immediate").SetFocus
           Application.SendKeys "^a"
           Application.SendKeys "{Del}"
     End Sub



Displaying each active VBA component in a worksheet

 
Sub ShowComponents()
    Dim VBP As VBProject
    Set VBP = ActiveWorkbook.VBProject
    NumComponents = VBP.VBComponents.Count
    For i = 1 To NumComponents
        Debug.Print VBP.VBComponents(i).name
        Select Case VBP.VBComponents(i).Type
            Case 1
                Debug.Print "Module"
            Case 2
                Debug.Print "Class Module"
            Case 3
                Debug.Print "UserForm"
            Case 100
                Debug.Print "Document Module"
        End Select
        Debug.Print VBP.VBComponents(i).CodeModule.CountOfLines
    Next i
End Sub



Find code object

 
Public Sub FindCodeObject()
  Dim component As VBIDE.VBComponent
  Set component = Workbooks("Book1.xls").VBProject.VBComponents(Workbooks("Book1.xls").CodeName)
  Debug.Print component.Name
End Sub



Find the code pane

 
Public Sub FindCodePane()
  Dim codePane As VBIDE.codePane
  Set codePane = Application.VBE.ActiveCodePane
  MsgBox codePane.TopLine
End Sub



Find the selected component in VBIDE

 
Public Sub FindSelectedComponent()
  Dim component As VBIDE.VBComponent
  Set component = Application.VBE.SelectedVBComponent
  MsgBox component.Name
End Sub



Find user form

 
Public Sub FindUserForm()
  
  Dim component As VBIDE.VBComponent
  Set component = Workbooks("Book1.xls").VBProject.VBComponents("UserForm1")
  MsgBox component.Name
End Sub



Find worksheet code module

 
Public Sub FindWorksheetCodeModule()
  Dim component As VBIDE.VBComponent
  Dim aWorkbook As Workbook
  Set aWorkbook = Workbooks("Book1.xls")
  Set component = aWorkbook.VBProject.VBComponents(aWorkbook.Worksheets("Sheet1").CodeName)
  MsgBox component.Name
End Sub



Get active project name

 
Public Sub ActiveProject()
  Dim project As VBIDE.VBProject
  Set project = Application.VBE.ActiveVBProject
  MsgBox project.Filename
End Sub



Get VB project name

 
Option Explicit
Private VBE As VBIDE.VBE
Public Sub FindProject()
  
  Dim project As VBIDE.VBProject
  Set project = Workbooks("Book1.xls").VBProject
  MsgBox project.Name
End Sub



Show selected VB component"s name

 
Public Sub ShowNames()
  With Application.VBE.SelectedVBComponent
    Debug.Print .Name & ": " & .Properties("Name")
  End With
End Sub