-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCommands.bas
More file actions
136 lines (112 loc) · 4.25 KB
/
Commands.bas
File metadata and controls
136 lines (112 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Attribute VB_Name = "Commands"
Option Explicit
Public Sub CloseAllCodeWindowsExceptActive(VBInstance As VBIDE.VBE)
Dim ActiveCodePane As CodePane
Set ActiveCodePane = VBInstance.ActiveCodePane
If ActiveCodePane Is Nothing Then
MsgBox "There are no open Code Panes", vbInformation
Exit Sub
End If
Dim Wind As Window
Dim ActiveCodePaneWindow As Window
Set ActiveCodePaneWindow = ActiveCodePane.Window
For Each Wind In VBInstance.Windows
If Wind.Type = vbext_wt_CodeWindow Then
If Not Wind Is ActiveCodePaneWindow Then
Wind.Close
End If
End If
Next
End Sub
Public Sub OpenMDIForm(Project As VBProject)
Dim component As VBComponent
For Each component In Project.VBComponents
If component.Type = vbext_ct_VBMDIForm Then
component.CodeModule.CodePane.Show
Exit Sub
End If
Next
MsgBox "An MDI Form Is not found in the Project", vbInformation
End Sub
Public Sub ExploreToPath(Path As String)
Shell PathName:="Explorer.exe /select,""" & Path & """", WindowStyle:=vbNormalFocus
End Sub
Public Function PathExists(strPath As String) As Boolean
PathExists = (Dir$(strPath) <> "")
End Function
Public Sub ActiveCodePaneOpenContainingFolder(VBInstance As VBIDE.VBE)
Dim ActiveCodePane As CodePane
Set ActiveCodePane = VBInstance.ActiveCodePane
If Not ActiveCodePane Is Nothing Then
With ActiveCodePane.CodeModule
OpenContainingFolder VBInstance, .Name, .Parent.Type
End With
End If
End Sub
Public Sub OpenContainingFolder(VBInstance As VBIDE.VBE, ComponentName As String, ComponentType As Integer)
Dim ProjectPath As String
ProjectPath = VBInstance.ActiveVBProject.FileName
Dim i As Integer
Dim Path As String
Dim pos As Integer
Dim FileName As String
Dim FileExtension As String
Select Case ComponentType
Case vbext_ComponentType.vbext_ct_ClassModule
FileExtension = "cls"
Case vbext_ComponentType.vbext_ct_PropPage
FileExtension = "pag"
Case vbext_ComponentType.vbext_ct_ResFile
FileExtension = "res"
Case vbext_ComponentType.vbext_ct_StdModule
FileExtension = "bas"
Case vbext_ComponentType.vbext_ct_UserControl
FileExtension = "ctl"
Case vbext_ComponentType.vbext_ct_VBForm
FileExtension = "frm"
Case Else
FileExtension = ""
End Select
FileName = ComponentName & "." & FileExtension
pos = InStrRev(ProjectPath, "\")
' Replace project file name with the file name of the component
Path = Left(ProjectPath, pos) & FileName
If PathExists(Path) Then
ExploreToPath Path
Else
' By default - navigate to the Project file location in the file system
ExploreToPath ProjectPath
End If
End Sub
Public Sub OpenStartUpObject(Project As VBProject)
If IsObject(Project.VBComponents.StartUpObject) Then
Dim StartUpForm As VBComponent
Set StartUpForm = Project.VBComponents.StartUpObject
StartUpForm.CodeModule.CodePane.Show
Else
Dim StartUpObject As Integer
StartUpObject = Project.VBComponents.StartUpObject
Select Case StartUpObject
Case vbext_StartupObject.vbext_so_SubMain
OpenStartupModule Project
Case vbext_StartupObject.vbext_so_None
MsgBox "The Project does not have any StartUp Object", vbInformation
End Select
End If
End Sub
Private Sub OpenStartupModule(Project As VBProject)
Dim component As VBComponent
Dim ModuleMember As Member
For Each component In Project.VBComponents
If component.Type = vbext_ct_StdModule Then
For Each ModuleMember In component.CodeModule.Members
If ModuleMember.Type = vbext_mt_Method And ModuleMember.Name = "Main" Then
component.CodeModule.CodePane.Show
component.CodeModule.CodePane.TopLine = ModuleMember.CodeLocation
Exit Sub
End If
Next
End If
Next
MsgBox "Could not find the Main Subroutine in the Project", vbInformation
End Sub