After Programmatically creating Personal Macro Workbook, Shortcut keys don't function.

pingme89

Board Regular
Joined
Jan 23, 2014
Messages
176
Office Version
  1. 365
Platform
  1. Windows
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:

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
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try adding the code "Application.OnKey "^{d}", "Fix2DigitPricing" somewhere in your code. This should make Ctrl+d run Fix2DigitPricing.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top