OK, I found the problem. I had another file open that I was working on to solve another thread here, and that had the shortcut of CTRL+r attached. I am starting to think I should troubleshoot other people's files in a sandboxed VM.
Here is the code that I ended up writing (this is Windows only, ENVIRON not available on a Mac):
Option Explicit
Public Sub ExportModules()
Dim OpenVBProject As VBProject
Dim CurrentVBComp As VBComponent
Dim Destination As String
Dim TextLine As String
Const ShortcutFlag = ".VB_Invoke_Func"
Dim PathRoot As String: PathRoot = Environ("HOMEPATH") & "\"
Dim Report As String: Report = PathRoot & "Shortcut Report.txt"
Dim SubName As String
Dim KeyboardShortcutRegEx As Object
Set KeyboardShortcutRegEx = CreateObject("VBScript.RegExp")
' Format of keyboard shortcut string in exported .bas file:
' Attribute [subname].VB_ProcData.VB_Invoke_Func = "[shortcutkey]\n14"
KeyboardShortcutRegEx.Pattern = "^Attribute ([^.]*)\..*VB_Invoke_Func = ""([^\\]*)\\n14""$"
On Error Resume Next ' in case file does not exit
Kill Report
On Error GoTo 0
Open Report For Output As #2
'Set OpenVBProject = Application.VBE.ActiveVBProject
For Each OpenVBProject In Application.VBE.VBProjects
On Error Resume Next ' some project causes errors on attempt to export,
' that is checked explicitly farther down
For Each CurrentVBComp In OpenVBProject.VBComponents
If CurrentVBComp.Type = vbext_ct_StdModule Then
Destination = PathRoot & OpenVBProject.Name & " " & CurrentVBComp.Name & ".bas"
CurrentVBComp.Export Destination
If Err.number > 0 Then
Debug.Print Destination & ": " & Err.number & " " & Err.Description
Err.Clear
Else
' Get the shortcut keys
' Read the .bas file, checking for RegEx matches
Open Destination For Input As #1
Do While Not EOF(1)
Line Input #1, TextLine
If KeyboardShortcutRegEx.test(TextLine) Then
SubName = KeyboardShortcutRegEx.Replace(TextLine, "$1")
Print #2, OpenVBProject.Name & " " & CurrentVBComp.Name & " " & SubName & _
": CTRL+" & KeyboardShortcutRegEx.Replace(TextLine, "$2")
End If
Loop
Close #1
Kill Destination ' comment this out if you would like to keep the .bas files
End If
End If
Next CurrentVBComp
Next OpenVBProject
Close #2
Shell "notepad " & Report, vbNormalFocus
End Sub
Bookmarks