Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:53:16+00:00 2026-06-17T15:53:16+00:00

I’m running a vbs file using a keyboard shortcut. Although the code runs fine,

  • 0

I’m running a vbs file using a keyboard shortcut. Although the code runs fine, the problem with vbs shortcuts is that the window in the foreground loses its focus as soon as you press the keyboard shortcut. (You can try it for yourself by placing an empty vbs file somewhere, a shortcut to the file in e.g. the start menu folder, a keyboard shortcut assigned to the shortcut and pressing the keyboard shortcut.)

I found that by using ALT+TAB, I could get the foreground window to regain focus. However, I’m unable to repeat this functionality in VBA. Apparently, ShellObject.SendKeys("%{TAB}") doesn’t work…

Is there any way to achieve the functionality of ALT+TAB in VBA? Thanks in advance.

EDIT

In the meanwhile, I made a switch to AutoIt to see if it could get me further. This is what I got:

ControlFocus("[CLASS:CabinetWClass]", "", "[CLASS:DirectUIHWND]")

I noticed that selecting the explorer window (i.e. CabinetWClass), is in some cases not enough. That’s why I’m setting focus on the control that actually contains the files/folders.

It’s working very well, but I’m still hoping for a VBA solution 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:53:16+00:00Added an answer on June 17, 2026 at 3:53 pm

    Can you use the Windows APIs to bring it back to the top? This works for me when run in Excel to bring the notepad to the top, so it should work. You would have to substitute the name of your window in the FindWindow call.

    Note: You should be really carefull with some of the flags because you’ll get some weird behaviour if you do some wrong combinations of them.

    Public Declare Function FindWindow Lib "user32" _
        Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
    
    
    Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As _
            Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As _
            Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
    'Either the handle of the window to position this window behind, or exactly one of the following flags stating where in the
    'Z-order to put the window:
    Private Const HWND_BOTTOM = 1             'Put the window at the bottom of the Z-order.
    Private Const HWND_NOTOPMOST = -2         'Put the window below all topmost windows and above all non-topmost windows.
    Private Const HWND_TOP = 0                'Put the window at the top of the Z-order.
    Private Const HWND_TOPMOST = -1           'Make the window topmost (above all other windows) permanently.
    
    'x: The x coordinate of where to put the upper-left corner of the window.
    'y: The y coordinate of where to put the upper-left corner of the window.
    'cx: The x coordinate of where to put the lower-right corner of the window.
    'cy: The y coordinate of where to put the lower-right corner of the window.
    
    'Flags: Zero or more of the following flags stating how to move the window:
    Private Const SWP_DRAWFRAME = &H20            'Same as SWP_FRAMECHANGED.
    Private Const SWP_FRAMECHANGED = &H20         'Fully redraw the window in its new position.
    Private Const SWP_HIDEWINDOW = &H80           'Hide the window from the screen.
    Private Const SWP_NOACTIVATE = &H10           'Do not make the window active after moving it unless it was already the active window.
    Private Const SWP_NOCOPYBITS = &H100          'Do not redraw anything drawn on the window after it is moved.
    Private Const SWP_NOMOVE = &H2                'Do not move the window.
    Private Const SWP_NOSIZE = &H1                'Do not resize the window.
    Private Const SWP_NOREDRAW = &H8              'Do not remove the image of the window in its former position, effectively leaving a ghost image on the screen.
    Private Const SWP_NOZORDER = &H4              'Do not change the window's position in the Z-order.
    Private Const SWP_SHOWWINDOW = &H40           'Show the window if it is hidden.
    
    
    Sub ShowWindow()
        Dim hwnd As Long 'handle to get the window
        Dim flags As Long ' the flags specifying how to move the window
        Dim retval As Long ' return value
    
        hwnd = FindWindow(vbNullString, "Untitled - Notepad")
        flags = SWP_NOSIZE Or SWP_DRAWFRAME
        retval = SetWindowPos(hwnd, HWND_TOP, 0, 0, 1, 1, flags) ' move the window
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.