https://drive.google.com/open?id=1CdDfhnoDPXkFVmJWIiUlv3BZ1u-jP9Pn 我使用Excel 2007时出错,但在Excel 2013中则正常 代码:
#If Win64 Then
Public Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
#Else
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
#End If
#If Win64 Then
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#Else
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If
答案 0 :(得分:2)
你应该尝试:
#If VBA7 Then
Public Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, _
ByVal nCmdShow As Long) As Long
#Else
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
#End If
#If VBA7 Then
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#Else
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If
与仅检查操作系统版本的Win64
不同,VBA7
检查您的办公套件是否为64位(而不是32位)。由于您无法在32位操作系统上使用64位Office,因此在两种情况下都基本上可以覆盖您。
即使你在64位操作系统中使用32位办公套件,你仍然可以使用,因为你的32位套件无论如何都会使用32位内存指针。您的操作系统可能必须转换它们,但这是操作系统要处理的问题。
但是,如果您更喜欢冗余,则可以使用And
运算符来检查两者:
#If VBA7 And Win64
但我个人而言,我只是使用VBA7
声明。
您说的“红线”不会影响您的代码。这是因为这两个语句中的一个是无效的,但是因为你在声明中使用了
#IF...#Then
语句,所以不会抛出错误。