0

I'm working within Microsoft Publisher.

I have a macro in module1 (that works) called "Export_as_Image".

I want to run this macro whenever I press F8.

I have created module2 with this code:

Sub SetKey()
Application.OnKey "{F8}", "Export_as_Image"
End Sub

When I run module2 I recieve the error "Compile error: Method or data member not found".

When I press F8 within Publisher, nothing happens.

Can anyone suggest what I may have done wrong, or a code to help me achieve what I'm looking for?

Thanks!

Charlie
  • 3
  • 1
  • After more searching, it seems that OnKey is not available within Publisher. Does anybody know of a work-around for this? – Charlie Jul 03 '22 at 12:34
  • I don't think there's a way in Publisher to use that key. You would have to add Export_as_image to your ribbon or quick access and use the built-in keyboard shortcuts. – Nicole M Jul 03 '22 at 15:18

1 Answers1

0

After some experimenting I found that it's needed to run SetKey for the first time firstly. You may call it from an event-driven sub (Workbook_Open, for example). Looks like running it for the first time, registers the key shortcut to the specified code.

Also, add the full path to the code you need to run: "Module2.Export_as_Image".

Update (reply to Charlie's comment below)

You can even move SetKey's code to Workbook_Open and delete SetKey (see image below).

Run on open

ENIAC
  • 813
  • 1
  • 8
  • 19