Skip to content

Commit 3161e08

Browse files
committed
Add formatting to the menu
1 parent 414da78 commit 3161e08

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ VbaDeveloper can also import the code again into your excel workbook. This is pa
88

99
A code formatter for VBA is also included. It is implemented in VBA and can be directly run as a macro within the VBA Editor, so you can format your code as you write it. The most convenient way to run it is by opening the immediate window and then typing 'format'. This will format the active codepane.
1010

11+
All functionality is also easily accessible via a menu. Look for the vbaDeveloper menu in the ribbon, under the addins section.
12+
1113
Building the addin
1214
-----------------------
1315

src/vbaDeveloper.xlam/Menu.bas

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ Public Sub createMenu()
1515

1616
Dim exSubMenu As CommandBarPopup
1717
Dim imSubMenu As CommandBarPopup
18+
Dim formatSubMenu As CommandBarPopup
1819
Set exSubMenu = addSubmenu(rootMenu, 1, "Export code for ...")
1920
Set imSubMenu = addSubmenu(rootMenu, 2, "Import code for ...")
21+
Set formatSubMenu = addSubmenu(rootMenu, 3, "Format code for ...")
2022
addMenuSeparator rootMenu
2123
Dim refreshItem As CommandBarButton
2224
Set refreshItem = addMenuItem(rootMenu, "Menu.refreshMenu", "Refresh this menu")
@@ -35,10 +37,13 @@ Public Sub createMenu()
3537
caption = projectName & " (" & Dir(project.fileName) & ")" '<- this can throw error
3638
Dim exCommand As String
3739
Dim imCommand As String
40+
Dim formatCommand As String
3841
exCommand = "'Menu.exportVbProject """ & projectName & """'"
3942
imCommand = "'Menu.importVbProject """ & projectName & """'"
43+
formatCommand = "'Menu.formatVbProject """ & projectName & """'"
4044
addMenuItem exSubMenu, exCommand, caption
4145
addMenuItem imSubMenu, imCommand, caption
46+
addMenuItem formatSubMenu, formatCommand, caption
4247
nextProject:
4348
Next vProject
4449
On Error GoTo 0 'reset the error handling
@@ -105,3 +110,19 @@ Public Sub importVbProject(ByVal projectName As String)
105110
importVbProject_Error:
106111
ErrorHandling.handleError "Menu.importVbProject"
107112
End Sub
113+
114+
Public Sub formatVbProject(ByVal projectName As String)
115+
On Error GoTo formatVbProject_Error
116+
117+
Dim project As VBProject
118+
Set project = Application.VBE.VBProjects(projectName)
119+
Formatter.formatProject project
120+
MsgBox "Finished formatting code for: " & project.name & vbNewLine _
121+
& vbNewLine _
122+
& "Did you know you can also format your code, while writing it, by typing 'format' in the immediate window?"
123+
124+
On Error GoTo 0
125+
Exit Sub
126+
formatVbProject_Error:
127+
ErrorHandling.handleError "Menu.formatVbProject"
128+
End Sub

0 commit comments

Comments
 (0)