从 Access VBA 以只读方式打开任意文件
我有一个 Access 应用程序,当前正在使用 fhandlefile() 过程: http://access.mvps.org/access/api/api0018.htm ...打开任意文件。
我希望能够将该例程包装在我自己的过程中,例如 OpenFile(strFilePath, bolReadOnly) ,以便我可以根据需要以只读方式打开文件。但是,我在 Shell API 调用中没有看到可以执行此操作的任何地方。我已经想到的两个替代解决方案(但有问题)是:
- 在打开文件之前将文件属性更改为只读,然后在打开文件后立即将其更改回来。但这是一个奇怪的解决方案,因为用户必须拥有足够的权限才能执行此操作,这通常与整个“以只读方式打开文件”相矛盾。
- 使用与文件类型相关的 API 以只读方式打开某些类型的文件(例如 Word 文档)。这是一个问题,因为我不想区分所有不同的文件类型,并且我想尽可能远离额外的库。
有人对我如何调整现有的例程或用其他可以实现这一点的东西替代有任何想法吗?
I have an Access application that's currently using the fhandlefile() procedure here:
http://access.mvps.org/access/api/api0018.htm
...to open arbitrary files.
I'd like to be able wrap that routine in my own procedure like OpenFile(strFilePath, bolReadOnly) so that I can open files as read-only as needed. However, I don't see anywhere in that Shell API call where I could do that. Two alternative solutions I've already thought of (but have issues) are:
- Change the file attributes just before opening the file to be read-only, then change them back right after opening it. This is a weird solution though because the user has to have sufficient privileges in order to do this, which usually contradicts the whole "opening file as read-only" thing.
- Use file-type-dependent APIs to open certain types of files (Word documents for example) as read-only. This is a problem because I don't want to have to case out all different file types, and I want to stay away from extra libraries as much as possible.
Anyone have any ideas on how I can tweak my existing routine or substitute it with something else that would allow this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您正在调用的 API...
尝试使用对 ShellExecte 使用默认动词打开文件(如果可用)。如果没有,则使用“open”动词。
如果失败,它会尝试使用“打开方式...”对话框打开文件,请参阅如何使用 _shellexecute 调用“打开方式...”对话框
这两种方法都使用关联的信息使用文件打开正确的应用程序,但无法通过“只读”。我的猜测是,这是因为并非每种文件类型都有只读甚至可写上下文。
您也可以在 Web 浏览器中打开该文件。
例如(使用对“Microsoft Internet Controls”的引用,通常位于 c:\windows\system32\ieframe.dll)
Looking at the API you're calling it...
Tries to open the using a call to ShellExecte to open the file with using the default verb is used, if available. If not, the "open" verb is used.
If that fails it tries to open the file using the Open With... dialog see How To Invoke the "Open With..." Dialog Box Using _shellexecute
Both these methods use the information associated with the file to open the correct application, but there's no way to pass "Read-only". My guess is that this is because not every file type has a readonly or even an writeable context.
You could as an alternative open the file in a Web Browser.
For example (using a reference to "Microsoft Internet Controls" Typically found at c:\windows\system32\ieframe.dll)