我已经在装有 Office 2010 的新 64 位计算机上使用我的内部工具的人遇到过此问题。
我所要做的就是更改代码行,如下所示:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
To This:
#If VBA7 Then
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#Else
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If
当然,您会希望确保您正在使用的库在两台机器上都可用,但到目前为止我使用的都没有出现问题。
请注意,在旧的 VB6 中,PtrSafe 甚至不是一个有效的命令,因此它会显示为红色,就好像您有编译错误一样,但它实际上不会给出错误,因为编译器将跳过if 块。
使用上述代码的应用程序可以在 Office 2003、2007 和 2010 32 位和 64 位上完美编译和运行。