我想要AHK代码可以允许打开资源管理器并选择活动的Microsoft Word文件。 Word似乎没有允许直接获取当前打开文件的路径的命令。但是在单词选择文档位置允许显示和选择当前打开文件的完整路径。后来我尝试使用AHK代码在资源管理器中选择文件。
#If WinActive("ahk_class OpusApp")
;In word highlight the document location box
#,::
send ^c ; copy the file path from document location
clipwait
run explorer.exe /select, "%clipboard%
return
到目前为止没有运气,它只是打开资源管理器,没有按预期选择文件。
答案 0 :(得分:0)
我认为你这是错误的做法。编写一个小的VBA宏,您可以将其存储在Normal模板中。
Microsoft Word VBA有ActiveDocument.Path
和ActiveDocument.Name
,可以与\
之间连接,以获取包含其路径的完整文档名称。
答案 1 :(得分:0)
要使用组件对象模型在AutoHotkey中检索打开和活动Word文档的完整文件路径和名称,请使用以下代码:
ActiveFileFullName := ComObjActive("Word.Application").ActiveDocument.FullName
上进一步阅读@ MSDN
此外,这是您在使用COM的AutoHotkey中寻找的代码。
按F1 - >检索打开的Word文档路径和文件名 - >打开资源管理器 - > 导航到文件夹 - >选择文件
;Press F1 while MicroSoft Word is open.
SetTitleMatchMode, 2
#IfWinExist, ahk_class OpusApp
F1::
ActiveDocumentFile := ComObjActive("Word.Application").ActiveDocument.FullName
SplitPath, ActiveDocumentFile, FileName, FolderPath
RunWait, Explorer
sleep 100
WinActivate, ahk_class CabinetWClass
WinWaitActive, ahk_class CabinetWClass
sleep 100
Explorer_NavSelect(FolderPath, FileName)
Return
Explorer_NavSelect(Path, File, hwnd="") {
hwnd := (hwnd="") ? WinExist("A") : hwnd
WinGet, ProcessName, ProcessName, % "ahk_id " hwnd
if (ProcessName != "explorer.exe")
return
For pExp in ComObjCreate("Shell.Application").Windows
{
if (pExp.hwnd = hwnd) { ; matching window found
pExp.Navigate("file:///" Path) ; Navigate to folder
sleep 100
pExp.Document.SelectItem(File, 1 8 16) ; Select our File
Return
}
}
}