diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d228976 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2014 Hilkoc + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 274dc81..d292ad2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Whenever you save your vba project the addin will *automatically* export all you VbaDeveloper can also import the code again into your excel workbook. This is particularly useful after reverting an earlier commit or after merging branches. Whenever you open an excel workbook it will ask if you want to import the code for that project. -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 ' application.run "format" '. This will format the active codepane. +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 ' application.run "formatActiveCodePane" '. This will format the active codepane. Besides the vba code, the addin also imports and exports any named ranges. This makes it easy to track in your commit history how those have changed or you can use this feature to easily transport them from one workbook to another. diff --git a/src/vbaDeveloper.xlam/Build.bas b/src/vbaDeveloper.xlam/Build.bas index 769f270..82b82ca 100644 --- a/src/vbaDeveloper.xlam/Build.bas +++ b/src/vbaDeveloper.xlam/Build.bas @@ -6,20 +6,33 @@ Attribute VB_Name = "Build" ' 2. From tools references... add ' * Microsoft Visual Basic for Applications Extensibility 5.3 ' * Microsoft Scripting Runtime -' 3. Rename the project to 'vbaDeveloper' +' 3. Rename the project to 'vbaDeveloper' (in Project Explorer (Ctrl+R to show) select current project and click F4 +' to open Properties window. Then set property '(Name)' to 'vbaDeveloper') ' 4. Enable programatic access to VBA: ' File -> Options -> Trust Center, Trust Center Settings, -> Macros, -' tick the box: 'Enable programatic access to VBA' (In excel 2010: 'Trust access to the vba project object model') +' tick the box: 'Enable programatic access to VBA' (In excel 2010: 'Trust access to the vba project object model') +' If you policy seetings don't allow to change this option you can create the following registry key: +' [HKEY_CURRENT_USER\Software\Policies\Microsoft\office\{Excel-Version}\excel\security] +' "accessvbom"=dword:00000001 ' If you get 'path not found' exception in Excel 2013, include the following step: -' In 'Trust Center' settings, go to 'File Block Settings' and check 'open' and/or 'save' +' In 'Trust Center' settings, go to 'File Block Settings' and un-check 'open' and/or 'save' ' for 'Excel 2007 and later Macro-Enabled Workbooks and Templates'. -' 5. If using a non-English version of Excel, rename your current workbook into ThisWorkbook (in VB Editor, press F4, -' then under the local name for Microsoft Excel Objects, select the workbook. Set the property '(Name)' to ThisWorkbook) -' 6. In VB Editor, press F4, then under Microsoft Excel Objects, select ThisWorkbook.Set the property 'IsAddin' to TRUE -' 7. In VB Editor, menu File-->Save Book1; Save as vbaDeveloper.xlam in the same directory as 'src' +' 5. If using a non-English version of Excel, rename your current workbook into ThisWorkbook (in VB Editor, press Ctrl+R, +' then in the Project Explorer (under the local folder name for Microsoft Excel Objects) select the workbook. Set the +' property (F4 to show Properties window) '(Name)' to ThisWorkbook). +' 6. In VB Editor, press F4, then under Microsoft Excel Objects, select ThisWorkbook in vbaDeveloper. Set the property 'IsAddin' to TRUE +' 7. In VB Editor, menu File-->Save Book1; Save as vbaDeveloper.xlam in the same directory as 'src' and the 'README.md' file ' 8. Close excel. Open excel with a new workbook, then open the just saved vbaDeveloper.xlam -' 9. Let vbaDeveloper import its own code. Put the cursor in the function 'testImport' and press F5 -' 10.If necessary rename module 'Build1' to Build. Menu File-->Save vbaDeveloper.xlam +' 9. Let vbaDeveloper import its own code: Put the cursor in the function 'testImport' and press F5 +' 10.Right click on 'vbaDeveloper', Import File for: +' * CustomActions.cls +' * EventListener.cls +' * MyCustomActions.cls +' 11.Read the instructions in ThisWorkbook in vbaDeveloper Project and uncomment the code if you want automatic import and export enabled +' 12.If necessary rename module 'Build1' to Build. Menu File-->Save vbaDeveloper.xlam +' 13.Open the Excel workbook where you want to use vbaDeveloper and add vbaDeveloper.xlam as reference to load the Add-In with the workbook: +' In VB Editor -> Tools -> References -> Browse and select vbaDeveloper.xlam +' Save the workbook, close it and reopen the workbook, now in the menu ribbon the ADD-INS tab is available with the VbaDeveloper menu ''' Option Explicit diff --git a/src/vbaDeveloper.xlam/EventListener.cls b/src/vbaDeveloper.xlam/EventListener.cls index 885a0ae..21cf8dc 100644 --- a/src/vbaDeveloper.xlam/EventListener.cls +++ b/src/vbaDeveloper.xlam/EventListener.cls @@ -29,7 +29,7 @@ Private Sub App_WorkbookAfterSave(ByVal wb As Workbook, ByVal success As Boolean If success Then Build.exportVbaCode wb.VBProject NamedRanges.exportNamedRanges wb - MsgBox "Finished saving workbook: " & wb.name & " . Code is exported." + MsgBox "Finished saving workbook: " & wb.name & ". Code is exported." Else MsgBox "Saving workbook: " & wb.name & " was not successful. Code is not exported." End If diff --git a/src/vbaDeveloper.xlam/Formatter.bas b/src/vbaDeveloper.xlam/Formatter.bas index f487c72..b3b1357 100644 --- a/src/vbaDeveloper.xlam/Formatter.bas +++ b/src/vbaDeveloper.xlam/Formatter.bas @@ -189,7 +189,7 @@ Public Sub formatProject(vbaProject As VBProject) Next End Sub -Public Sub format() +Public Sub formatActiveCodePane() formatCode Application.VBE.ActiveCodePane.codeModule End Sub diff --git a/src/vbaDeveloper.xlam/Menu.bas b/src/vbaDeveloper.xlam/Menu.bas index f420438..e8c9544 100644 --- a/src/vbaDeveloper.xlam/Menu.bas +++ b/src/vbaDeveloper.xlam/Menu.bas @@ -164,7 +164,7 @@ Public Sub formatVbProject(ByVal projectPath As String) Formatter.formatProject project MsgBox "Finished formatting code for: " & project.name & vbNewLine _ & vbNewLine _ - & "Did you know you can also format your code, while writing it, by typing 'application.Run ""format""' in the immediate window?" + & "Did you know you can also format your code, while writing it, by typing 'application.Run ""formatActiveCodePane""' in the immediate window?" On Error GoTo 0 Exit Sub