I have created a Personal Macro Workbook with VBA. I than added a Module with code. However, after the Personal Macro Workbook was created, and the code is present, I can't invoke the procedure with a shortcut key.
I used the following code:
I used the following code:
VBA Code:
Dim personalWB As Workbook
Dim vbaModule As Object
Dim code As String
' Open the Personal Macro Workbook
On Error Resume Next
Set personalWB = Workbooks("PERSONAL.XLSB")
On Error GoTo 0
' If it's not open, open it
If personalWB Is Nothing Then
Set personalWB = Workbooks.Open(Application.UserLibraryPath & "PERSONAL.XLSB")
End If
' Add a new module to the Personal Macro Workbook
Set vbaModule = personalWB.VBProject.VBComponents.Add(vbext_ct_StdModule)
' Define the procedure code
Code1 = _
"Sub Fix2DigitPricing()" & vbCrLf & _
"'" & vbCrLf & _
"' Fix2DigitPricing Macro" & vbCrLf & _
"'" & vbCrLf & _
"' Keyboard Shortcut: Ctrl+d" & vbCrLf & _
"'" & vbCrLf & _
"End Sub"
' Add the procedure code to the new module
vbaModule.CodeModule.AddFromString Code1