diff --git a/src/vbaDeveloper.xlam/Build.bas b/src/vbaDeveloper.xlam/Build.bas index 268229e..ab5af83 100644 --- a/src/vbaDeveloper.xlam/Build.bas +++ b/src/vbaDeveloper.xlam/Build.bas @@ -12,7 +12,7 @@ Attribute VB_Name = "Build" ' 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 +' "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 un-check 'open' and/or 'save' ' for 'Excel 2007 and later Macro-Enabled Workbooks and Templates'. @@ -30,7 +30,7 @@ Attribute VB_Name = "Build" ' 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 +' 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 @@ -147,13 +147,30 @@ Public Sub exportVbaCode(vbaProject As VBProject) End Sub +Private Function codeModuleExists(component As VBComponent) As Boolean + On Error GoTo doesnt + Dim tempObj + Set tempObj = component.codeModule + codeModuleExists = True + Exit Function +doesnt: + On Error GoTo -1 + Err.Clear + codeModuleExists = False + Exit Function +End Function + + Private Function hasCodeToExport(component As VBComponent) As Boolean hasCodeToExport = True - If component.codeModule.CountOfLines <= 2 Then - Dim firstLine As String - firstLine = Trim(component.codeModule.lines(1, 1)) - 'Debug.Print firstLine - hasCodeToExport = Not (firstLine = "" Or firstLine = "Option Explicit") + If codeModuleExists(component) Then + If component.codeModule.CountOfLines <= 2 Then + Dim firstLine As String + firstLine = Trim(component.codeModule.lines(1, 1)) + 'Debug.Print firstLine + hasCodeToExport = Not (firstLine = "" Or firstLine = "Option Explicit") + Else + hasCodeToExport = False End If End Function