Results 1 to 9 of 9
  1. #1
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,832
    Thanks
    136
    Thanked 484 Times in 461 Posts

    Excel lostfocus (Excel2003)

    I have an application in which I have a top panel (non-Excel) which allows a User to select and set some data parameters.
    In a lower panel I have an Excel workbook displaying a sheet (on which there are several buttons that display Forms and buttons that run various macros within the Excel workbook).

    If the User clicks in the top panel (non Excel area) and then clicks on the Excel worksheet area below, the keyboard appears 'locked' in the Excel worksheet e.g. using the cursor keys does not move the cellpointer within the worksheet.
    The User is able to click into different cells in the worksheet (but cannot navigate to different cells using the keyboard or type numbers etc).
    It seems as if Excel has 'lost the focus'.
    However, the User can click some of the buttons on the sheet - the macros will run, but on completion the keyboard still appears 'locked'.

    It turns out that I can clear the 'locked' state by simply clicking on
    File-Properties-Cancel
    or
    Tools-Options-Cancel
    ..in the Excel command bar.

    Is there anything related to a 'get focus' option that I could include in a VBA routine that would give the focus fully back to Excel??
    I have tried my usual suspects like
    ThisWorkbook.Activate
    and even
    Application.EnableEvents = True
    ..but so far no luck.

    If I double-click in the spreadsheet (to enter cell Edit mode) and then press [Esc], I get the focus back.

    Any suggestions on what may be going on??

    Regards

    zeddy

    PS. the other application is SAP

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel lostfocus (Excel2003)

    Do you start Excel using code? If so, how?

  3. #3
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,832
    Thanks
    136
    Thanked 484 Times in 461 Posts

    Re: Excel lostfocus (Excel2003)

    OK Hans, you got me.

    'Excel' is started by the SAP application.
    (I believe it is a custom implementation of Excel i.e. part of SAP?)
    If I click on the Excel help it tells me it is Excel2003 SP2

    zeddy

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel lostfocus (Excel2003)

    So it is an error in the way SAP starts Excel. We can't do anything about that.

  5. #5
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,832
    Thanks
    136
    Thanked 484 Times in 461 Posts

    Re: Excel lostfocus (Excel2003)

    Well maybe.
    I don't like to give up.

    SAP starts the Excel session OK and the User can do all sorts of stuff in the Excel workbook like entering data and running routines in the Excel workbook as normal.
    It's just that when the User clicks out of the Excel area and then clicks back into the Excel area again, the Excel focus seems to be 'semi-lost'.

    It isn't totally lost because the User can still click into various (unprotected) cells in the worksheets, can switch tabs to different sheets, or click macro buttons to execute various functions.

    It is 'cleared' if the User does some seemingly innocous thing like clicking
    Tools-Options-Cancel in the Excel top panel command bar
    or even pretending to run a macro like
    Tools-Macro-Macros-Cancel

    I'm just trying to see if there is anything I can append to an existing macro (or create a separate one and attach it to a button e.g. [click me if your keyboard is stuck] .
    But I've never hear of an Excel..
    Application.SetFocus = True
    ..or similar

    zeddy

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel lostfocus (Excel2003)

    You could try

    ActiveWindow.RangeSelection.Select

    or perhaps

    AppActivate "Microsoft Excel"

    No idea whether they will work, but it's worth a try.

  7. #7
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,832
    Thanks
    136
    Thanked 484 Times in 461 Posts

    Re: Excel lostfocus (Excel2003)

    Thanks Hans

    I tried both but no luck.
    The AppActivate "Microsoft Excel" gave an invalid procedure call.
    ActiveWindow.RangeSelection.Select still left the keyboard 'locked'
    (Actually, cursor key movement moved the selection in the 'SAP window' )

    zeddy
    zeddy

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel lostfocus (Excel2003)

    I'm out of ideas then, sorry.

  9. #9
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,832
    Thanks
    136
    Thanked 484 Times in 461 Posts

    Re: Excel lostfocus (Excel2003)

    Many thanks for your suggestions Hans.

    I will set this aside.
    I am still puzzled of course.
    Maybe it's another one of those things you can do directly in Excel but can't do or replicate the result in VBA.

    regards

    zeddy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •