Gå til hovedindhold

Hvordan holder Excel-vinduet altid øverst?

Har du nogensinde ønsket, at dine Excel-vinduer altid skal være på toppen og ikke bliver dækket af andre vinduer? Desværre indeholder Excel ikke en funktion til løsning af denne opgave. Men her kan jeg give dig en VBA-kode til at håndtere dette job.

Hold Excel-vinduet altid øverst med VBA-kode


pil blå højre boble Hold Excel-vinduet altid øverst med VBA-kode

Følgende VBA-kode kan hjælpe dig med at holde Excel-vinduet altid øverst, koden anvendes på både office 32-bit og office 64-bit.

1. Hold nede ALT + F11 nøgler til at åbne Vinduet Microsoft Visual Basic til applikationer.

2. Klik indsatte > Moduler, og indsæt følgende kode i Modul vindue.

VBA-kode: Hold Excel-vinduet altid øverst

'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

3. Tryk derefter på F5 nøgle til at køre denne kode, og en Makroer dialogboks vises, vælg SetXLOnTop valgmulighed og klik Kør .

doc-keep-excel-on-top-1

4. Og så vil dit Excel-vindue altid være oven på andre applikationer.

Bemærk: Hvis du vil bringe Excel-vinduet tilbage til det normale, skal du bare trykke på F5 nøgle til at åbne Makroer dialog, vælg SetXNormal og klik Kør.

Bedste kontorproduktivitetsværktøjer

🤖 Kutools AI Aide: Revolutionér dataanalyse baseret på: Intelligent udførelse   |  Generer kode  |  Opret brugerdefinerede formler  |  Analyser data og generer diagrammer  |  Aktiver Kutools funktioner...
Populære funktioner: Find, fremhæv eller identificer dubletter   |  Slet tomme rækker   |  Kombiner kolonner eller celler uden at miste data   |   Runde uden formel ...
Super opslag: VLookup med flere kriterier    Multiple Value VLookup  |   VOpslag på tværs af flere ark   |   Fuzzy Lookup ....
Avanceret rulleliste: Opret hurtigt rulleliste   |  Afhængig rulleliste   |  Multivælg rulleliste ....
Column Manager: Tilføj et bestemt antal kolonner  |  Flyt kolonner  |  Skift synlighedsstatus for skjulte kolonner  |  Sammenlign områder og kolonner ...
Fremhævede funktioner: Grid fokus   |  Designvisning   |   Stor Formel Bar    Arbejdsbog & Ark Manager   |  Ressourcebibliotek (Autotekst)   |  Datovælger   |  Kombiner regneark   |  Krypter/Dekrypter celler    Send e-mails efter liste   |  Superfilter   |   Specielt filter (filter fed/kursiv/gennemstreget...) ...
Top 15 værktøjssæt12 tekst Værktøjer (tilføje tekst, Fjern tegn, ...)   |   50 + Chart Typer (Gantt kort, ...)   |   40+ Praktisk formler (Beregn alder baseret på fødselsdag, ...)   |   19 Indsættelse Værktøjer (Indsæt QR-kode, Indsæt billede fra sti, ...)   |   12 Konvertering Værktøjer (Tal til ord, Valutaomregning, ...)   |   7 Flet og del Værktøjer (Avancerede kombinere rækker, Opdel celler, ...)   |   ... og mere

Overlad dine Excel-færdigheder med Kutools til Excel, og oplev effektivitet som aldrig før. Kutools til Excel tilbyder over 300 avancerede funktioner for at øge produktiviteten og spare tid.  Klik her for at få den funktion, du har mest brug for...

Beskrivelse


Fanen Office bringer en grænseflade til et kontor med Office, og gør dit arbejde meget lettere

  • Aktiver redigering og læsning af faner i Word, Excel, PowerPoint, Publisher, Access, Visio og Project.
  • Åbn og opret flere dokumenter i nye faner i det samme vindue snarere end i nye vinduer.
  • Øger din produktivitet med 50 % og reducerer hundredvis af museklik for dig hver dag!
Comments (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hey thanks was finding this for years.
This comment was minimized by the moderator on the site
awesome!!!!!!
This comment was minimized by the moderator on the site
awesome!!!!!!
This comment was minimized by the moderator on the site
Does this code have to be applied to each excel file separately or can the macro be saved within excel to be toggled on/ off whenever a new Excel workbook is open?
This comment was minimized by the moderator on the site
Hello

It seems that xHwnd defined to store Application.hWnd before calling SetWindowPos as below:

xHwnd = Application.hWnd
Call SetWindowPos(xHwnd, xStype, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)

Thanks
This comment was minimized by the moderator on the site
Absolute genius. Exactly what I needed. Thanks!!!
This comment was minimized by the moderator on the site
Thanks so much for this! I needed to keep my automated system stats sheet up at all times while I did other things based on what it was showing me. Very helpfull! :D
This comment was minimized by the moderator on the site
Thanks .. God Bless..!
This comment was minimized by the moderator on the site
Thanks for this. Very helpful when transposing data from multiple systems onto a spread sheet. Appreciate the code!
This comment was minimized by the moderator on the site
Thanks for the help!!! I had to use this as a workaround because you cant have two workpages open at the same time. Appreciate you sharing your code :)
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations