此代码确定当前打开的资源管理器窗口, 我想打开列表中的第一个,如果列表为空,请打开一个 而是新的资源管理器。
我希望在当前鼠标位置打开/激活任一窗口
Sub Test()
Call ClearNamedRanges(Sheet1.Range("A1:A35000"))
End Sub
Private Sub ClearNamedRanges(ByRef oNameRange As Range)
Dim oName As Name
For Each oName In ActiveWorkbook.Names
'if Not IsError(Application.Match(oName.Name, oNameRange, 0)) Then oName.RefersToRange.ClearContents
If Not oNameRange.Find(oName.Name) Is Nothing Then oName.RefersToRange.ClearContents
Next
End Sub
答案 0 :(得分:0)
这解决了。 -但是可以优化,任何人有什么建议吗?
#e::
list := ""
numberOfwindows := ""
wins := ""
WinGet, id, list, ahk_class CabinetWClass ahk_exe explorer.exe
Loop, %id%
{
numberOfwindows := A_Index
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
if (A_Index = 1) { ; if it's the first index of the loop
;MsgBox %title%
win = %title% ; store the title in " win "
}
wins .= A_Index A_Space title ?½½ A_Index A_Space title "`n" : ""
}
IfWinNotExist ahk_class CabinetWClass
{
Run C:\Windows\explorer.exe
win := File Explorer
WinWait, %win% ahk_class CabinetWClass
WinMove, mxpos_new , mypos_new
WinActivate
}
;MsgBox, number of explorer windows = %numberOfwindows%`n`n%wins%
; above msgbox displays number and the names of the windows.
;~ ; we now know the win
; and its title, exe and class.
; we want it's current position.
WinGetPos, X, Y, Width, Height,%win% ahk_class CabinetWClass
;MsgBox, %X%, %Y%, %Width%, %Height%
; and we want the mouse position.
CoordMode, Mouse, Screen ; Coordinates are relative to the desktop (entire screen).
MouseGetPos, mxpos , mypos,
;MsgBox, %mxpos%, %mypos%
mxpos_new := mxpos - (Width / 2)
mypos_new := mypos - (Height / 2)
;MsgBox, %mxpos% %mypos% %Width% %Height% %mxpos_new% %mypos_new%
; activate that specific window
WinWait, %win% ahk_class CabinetWClass
WinMove, mxpos_new , mypos_new
WinActivate
return