Skip to main content

Kutools for Office — One Suite. Five Tools. Get More Done.

How to keep Excel window always on top?

Author Xiaoyang Last modified

Have you ever found it troublesome when your Excel window keeps getting hidden behind other applications while multitasking? Many users often want the Excel workbook window to remain in the foreground so they can refer to or input data into Excel while working with other programs, like when manually transferring numbers from a browser or another desktop app. This feature is especially useful for users who work with dual monitors, give presentations, or frequently toggle between Excel and other software.

Unfortunately, Microsoft Excel does not natively offer a built-in setting or option that allows you to make the Excel window always stay on top of other windows. Directly pinning Excel above all other open windows is not supported through its standard interface, regardless of your version or whether you use Office 32-bit or 64-bit. However, there is an alternative solution to achieve this functionality. Below, you’ll find a VBA code method suited for a range of usage scenarios.

Keep the Excel window always on top with VBA code


Keep the Excel window always on top with VBA code

This VBA code solution allows you to keep your active Excel window pinned above all other windows, ensuring it is always visible and not overlapped by other application windows. Whether you're using a 32-bit or 64-bit version of Office, the VBA script provided below works for both versions. This approach is especially suitable for advanced Excel users or those in environments where installing additional software is not allowed.

Before proceeding, save your work, as unexpected errors or Excel restarts may occasionally occur when running macros. Also, note that this solution only affects the Excel window you execute the macro; other instances will not automatically remain on top.

1. Hold down the ALT + F11 keys on your keyboard to launch the Microsoft Visual Basic for Applications editor window. This is the environment where you can enter and manage VBA code for your Excel workbooks.

2. In the VBA editor, click Insert > Module to add a new module to your workbook. Then, copy and paste the following VBA code into the opened Module window:

VBA code: Keep Excel window always on top

'Update 20140909
#If Win64 Then
    Public Declare PtrSafe Function SetWindowPos _
        Lib "user32" ( _
            ByVal hwnd As LongPtr, _
            ByVal hwndInsertAfter As LongPtr, _
            ByVal x As Long, ByVal y As Long, _
            ByVal cx As Long, ByVal cy As Long, _
            ByVal wFlags As Long) _
    As Long
#Else
    Public Declare Function SetWindowPos _
        Lib "user32" ( _
            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
#End If
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Sub ShowXLOnTop(ByVal OnTop As Boolean)
    Dim xStype As Long
    #If Win64 Then
        Dim xHwnd As LongPtr
    #Else
        Dim xHwnd As Long
    #End If
    If OnTop Then
        xStype = HWND_TOPMOST
    Else
        xStype = HWND_NOTOPMOST
    End If
    Call SetWindowPos(Application.hwnd, xStype, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
End Sub
Sub SetXLOnTop()
    ShowXLOnTop True
End Sub
Sub SetXLNormal()
    ShowXLOnTop False
End Sub

This code uses system-level API calls to control the window's pinning status. Please ensure that macros are enabled in your Excel settings so that the VBA code will function properly. If you encounter a "Macros are disabled" message, you may need to update your Excel Trust Center settings to allow macro execution.

3. After entering the code, press F5 or click the Run button in the VBA editor. A Macros dialog box will appear listing available macros. Select the macro named SetXLOnTop and then click Run to execute it. This will apply the "always on top" status to your current Excel window. See the illustration below:

a screenshot showing how to run the code

4. Once the macro finishes running, your Excel window should remain visible above all other opened applications, making it much easier to reference or input data across multiple programs without the Excel window being hidden.

This setting will persist until you manually revert it. If you minimize and restore the window, the "always on top" status is typically preserved, but closing and reopening Excel will require running the macro again.

Note: If you wish to return your Excel window to normal so that it is no longer always on top, repeat the activation process: press F5 to open the Macros dialog, choose the SetXNormal macro, and click Run. Your Excel window will then behave as usual.

Troubleshooting Tips: If you receive an error when running the macro, double-check your macro security settings and ensure all macro code is pasted correctly. Some corporate environments may restrict certain window management operations, so consult with IT if the method does not work as expected. Also, make sure you are running Excel as a standard user; running as an administrator is typically not required for this task.

This VBA solution is ideal if you don’t want to install third-party software and are comfortable using Excel’s built-in scripting functions. However, if you frequently need to pin windows from multiple applications, you may prefer a tool dedicated to managing window positions.


Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

All Kutools add-ins. One installer

Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.

Excel Word Outlook Tabs PowerPoint
  • All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
  • One installer, one license — set up in minutes (MSI-ready)
  • Works better together — streamlined productivity across Office apps
  • 30-day full-featured trial — no registration, no credit card
  • Best value — save vs buying individual add-in