通常需要快速找到打开的活动文件的文件夹位置,并在处理不同的软件应用程序时突出显示或选择活动文件。快速查找在相同文件夹中查找相关文件所需的驻留文件夹,重命名已打开文件或驻留文件夹或将文件移动到不同的相关文件夹。当前选项需要浏览文件夹的负载以查找和定位特定文件夹,其中包含大量类似的其他文件(类似于在大海捞针中查找针)。 Microsoft Office套件具有名为“文档位置”的内置功能,可以将其添加到快速访问工具栏中。但它只允许查看文件夹位置或完整路径,但没有单击命令或可用键(AFAIK)方便地跳转到该定位文件夹并突出显示/识别打开的文件,以便可以进行进一步操作(例如重命名,移动)在该特定文件/文件夹上。对于其他软件应用程序也是如此,其中本机程序具有获取完整路径但无法跳转到特定文件/文件夹的选项。考虑一个Microsoft Office套件应用程序(例如word)作为测试用例,我可以想象如下的过程;
在我对上述任务的实施评估中,可能性如下
我在任务3中遇到了困难,我尝试了其中的每一个,但到目前为止没有运气
Clipboard := “fullpath” ; Full path (D:\Folder\Subfolder\Mywordfile.docx ) copied from Word
Run explorer /e, “Clipboard”
Run %COMSPEC% /c explorer.exe /select`, "%clipboard%"
到目前为止,explorer命令只会将我带到不在特定文件夹位置(任务1中的路径)的文档文件夹中。我很好奇,知道什么是正确的资源管理器代码,为剪贴板中的给定完整路径选择文件。欣赏支持AHK代码或更好的方法来完成这项任务。提前谢谢。
答案 0 :(得分:2)
我不清楚为什么你的示例代码不起作用。我怀疑这是因为额外的角色。
运行此命令后,Windows资源管理器将打开并选择所需的文件(如果存在)。
FullPathFilename := "e:\temp\test.csv"
Explorer := "explorer /select," . FullPathFilename
Run, %Explorer%
答案 1 :(得分:2)
我不知道你是否尝试过其他方法,但我认为这更简单,更短:
1)将文档的完整路径存储在字符串中:oldfile = ActiveDocument.FullName
2)保存为ActiveDocument.SaveAs
3)使用Kill oldfile
所有这些都是直接来自VBA,不需要使用Explorer shell。其他应用程序也存在同样的情况。
以下是Word文档的完整工作代码:
Sub RenameActiveDoc()
Dim oldfile As String
Set myDoc = ActiveDocument
'1) store current file
oldfile = myDoc.FullName
'2) save as the active document (prompt user for file name)
myDoc.SaveAs FileName:=InputBox("Enter new name", "Rename current document", myDoc.Name)
'3) Delete the old file with
On Error GoTo FileLocked
Kill oldfile
On Error GoTo 0
Exit Sub
FileLocked:
MsgBox "Could not delete " & oldfile, vbInformation + vbOKOnly, "File is locked"
End Sub
答案 2 :(得分:0)
在Ro Yo Mi的贡献下,我能够提出以下解决方案。但是我假设可以更好地解决这个问题。
;;; Customize Document Location (Choose form All Commands) in Quick Access Toolbar and get its position (#4 for my case)
#If WinActive("ahk_class OpusApp") || WinActive("ahk_class XLMAIN") || WinActive("PPTFrameClass")
#p:: ;Close Word/Excel/PowerPoint Document and Locate in Explorer Folder Location
clipboard = ;empty the clipboard
Send !4 ; Select full path while document location at #4 position in Quick Access toolbar
Send ^c ; copy the full path
ClipWait ; waits for the clipboard to have content
Send {esc}
Send, ^{f4} ; Close opened document only but keep Word/Excel/PPT program running
Explorer := "explorer /select," . clipboard
Run, %Explorer%\
return