简体   繁体   English

如何从Windows 10计算机上的Microsoft Access VBA启动Metro应用

[英]How to Launch a Metro App from Microsoft Access VBA on Windows 10 Computer

I have a situation in which I wanted to utilize the camera app in Windows 10 from my Microsoft Access program. 我有一种情况,我想通过我的Microsoft Access程序在Windows 10中使用相机应用程序。 Normally I could just send a command to execute the program's executable, but with the metro app there is no straightforward executable. 通常,我可以发送命令来执行程序的可执行文件,但是对于Metro应用程序,没有简单的可执行文件。

The basic code I use is this: 我使用的基本代码是这样的:

Shell """" & PthToExe & """", vbNormalFocus

PthToExe is the path name for the executable. PthToExe是可执行文件的路径名。

I looked around a decent bit, but was unable to find any simple solutions and ended up coming up with my own. 我环顾四周,但找不到任何简单的解决方案,最终提出了自己的解决方案。 My solution is to make a shortcut link to the camera application and then to launch the link. 我的解决方案是建立指向相机应用程序的快捷链接,然后启动该链接。

In order to make a shortcut link in Windows 10, you can click on the start button, go to "All Apps", find the app you want (in my case "Camera"), and then click and drag it to the desktop. 为了在Windows 10中建立快捷链接,您可以单击开始按钮,转到“所有应用程序”,找到所需的应用程序(在我的情况下为“相机”),然后单击并将其拖到桌面上。

Now that you have a shortcut, you can launch the shortcut from a command line. 有了快捷方式后,您可以从命令行启动快捷方式了。 (So my shortcut doesn't clutter up my desktop, I dragged it off my desktop and into a folder on the "C" drive.) (因此,快捷方式不会使我的桌面杂乱无章,我将其从桌面上拖到了“ C”驱动器上的文件夹中。)

Type the path into a command prompt like this and hit enter to test launching your app: C:\\GJ\\Camera.lnk 在这样的命令提示符下键入路径,然后按Enter键以测试启动您的应用程序: C:\\GJ\\Camera.lnk

So that solves the problem if you wanted to launch from a command line. 因此,如果您想从命令行启动,则可以解决该问题。 For some reason, though, Access would not accept that command. 但是由于某种原因,Access不会接受该命令。 The way I got around it was I put the command in a batch file (Edit: Alternatively, see HansUp's comment). 解决该问题的方法是将命令放入批处理文件中(编辑:或者,请参见HansUp的注释)。 To do that, you just need to open notepad, type in the same thing you typed in the command prompt, save the note pad document, and then rename the document to have a .bat extension. 为此,您只需要打开记事本,在命令提示符下键入相同的内容,保存记事本文档,然后将文档重命名为扩展名为.bat。

You can then execute the .bat file from Microsoft Access as follows: 然后,您可以从Microsoft Access执行.bat文件,如下所示:

Shell "C:\\GJ\\OpenCamera.bat", vbMinimizedNoFocus

Note that normally, I use vbNormalFocus when running the shell command, but in this case, it is desirable not to see the little command prompt open before the actual program opens. 请注意,通常,我在运行shell命令时使用vbNormalFocus,但在这种情况下,最好不要在实际程序打开之前看到小命令提示符打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM