How to bring sheet back into focus after loading picture into Userform

xltrader100

New Member
Joined
Dec 8, 2009
Messages
17
My objective is to be able to use the up/down Arrow keys to step down a list of names in a column. Each step up/down puts a new picture into a Userform, which stays visible and floating above the sheet.

All of that works fine if I use the mouse to click on the next cell up or down, but when trying to use the Arrow keys the problem is that as soon as the picture gets loaded onto the form, the form takes focus, and the next Arrow keypress doesn't register until the sheet regains focus.

I'm looking for a VBA command that can bring the sheet back into focus, as if I clicked on the border of the sheet.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
If the code you have is not too long can you post it (or part of the code) here so we can take a look
 
Upvote 0
Here's a bare bones extraction of the relevant bits of the code. Each cell that I'm stepping down contains a filespec that leads to a picture file. Selecting one of those cells loads that picture onto the Userform. Then the Userform has focus and I can no longer tab to the next cell.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Dim picturePath$
   picturePath$ = Target.Value   ' e.g. picturePath$ = "C:\myProject\picture1.jpg"
   If picturePath$ Like ("*.jpg") Or picturePath$ Like ("*.wmf") Or picturePath$ Like ("*.bmp") Then
      '   If Not isThisFormLoaded("Userform1") Then
      '      Load UserForm1
      '      UserForm1.Show
      '   End If
      'userform1 pictureSizeMode is stretch, and is moveable and resizable
      UserForm1.Picture = LoadPicture(picturePath$)
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,570
Messages
6,120,294
Members
448,953
Latest member
Dutchie_1

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