Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Menu.exportVbProject" "CodeModule" runtime error -2147467259 #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/vbaDeveloper.xlam/Build.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand All @@ -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
Expand Down Expand Up @@ -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
Comment on lines +157 to +160
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
On Error GoTo -1
Err.Clear
codeModuleExists = False
Exit Function
codeModuleExists = False

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it simple. The error is already reset once it's caught by the 'doesnt' error handler.

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

Expand Down