如何使用 VBA 获取启动 ActiveDocument 的快捷方式的文件路径?
我正在构建一个文档管理系统。在主文档存储库的每个子目录中,都有一个文档模板的快捷方式。当用户想要创建新文档时,他/她导航到该文档的相应子目录并单击快捷方式。
当用户单击快捷方式时,MS Word 将启动,显示基于模板的新文档。当用户单击“保存”时,文档通常会保存到当前目录,该目录将是在“Word 选项”中指定的新文档的默认位置。
我希望新文档的当前目录与创建该文档的快捷方式的目录相同。用户已经通过导航到适当的子目录并单击快捷方式来决定文档的位置。用户无需在“另存为...”对话框中再次导航到同一位置。
如果我可以获得快捷方式的路径,我可以以编程方式将文档保存到同一目录或新的子目录中。
还在 MSDN VBA 论坛 以及 VBA Express。
I am building a document management system. In each subdirectory within the main document repository, there is a shortcut to a document template. When a user wants to create a new document, he/she navigates to the appropriate subdirectory for the document and clicks the shortcut.
When the user clicks the shortcut, MS Word is launched, showing the new document based on the template. When the user clicks Save, the document will normally be saved to the current directory which will be the default location for new documents specified in Word Options.
I want the current directory of a new document to be the same as the directory of the shortcut from which it was created. The user has already decided where the document is to be located by navigating to the appropriate subdirectory and clicking the shortcut. It should not be necessary for the user to navigate to the same location again within the Save As... dialog.
If I can obtain the path to the shortcut, I can programmatically save the document to the same directory or a new subdirectory.
Also asked on MSDN VBA Forum and on VBA Express.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为如果不对文件系统进行一些可怕的黑客攻击,你就无法做到这一点(我对快捷方式的“开始于”属性灵机一动,但遗憾的是这不起作用)。
不幸的是,我认为最好的解决方案可能是摆脱快捷方式,只保留大量文档模板的副本。
克里斯
I don't think you're going to be able to do this without doing some awful hacking around trawling the file system (I had a brainwave about the "Start in" property of the shortcut, but sadly that didn't work).
Unfortunately I think the best solution may be to get rid of the shortcuts and just have lots of copies of the document template lying around.
Chris
也许是这个?
Maybe this?