简体   繁体   English

代码VBA Excel 2007中的红线

[英]Red line in code vba Excel 2007

https://drive.google.com/open?id=1CdDfhnoDPXkFVmJWIiUlv3BZ1u-jP9Pn Error when I use Excel 2007, but in Excel 2013 then it normal code: 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

You should try: 你应该试试:

#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

Unlike Win64 which just checks the OS version, VBA7 checks whether your office suite is 64-bit (as opposed to 32-bit). Win64仅检查操作系统版本不同, VBA7检查您的办公套件是否为64位(而不是32位)。 Since you can't use 64-bit Office on a 32-bit OS, this essentially covers you in both cases. 由于您不能在32位操作系统上使用64位Office,因此这两种情况实际上都可以解决。

And even if you are using a 32-bit office suite within a 64-bit OS, you are still covered because of the fact your 32-bit suite will use 32-bit memory pointers anyway. 即使您在64位操作系统中使用32位办公套件,也仍然可以使用,因为您的32位套件仍将使用32位内存指针。 Your OS may have to convert them, but that's the OS' problem to deal with. 您的操作系统可能需要转换它们,但这是操作系统要解决的问题。

In the case you prefer the redundancy, however, you can use the And operator to check for both: 但是,在您更喜欢冗余的情况下,可以使用And运算符检查这两者:

#If VBA7 And Win64

But me personally, I just go with the VBA7 statement. 但是我个人而言,我只接受VBA7声明。

The "red line" you speak of will not affect your code. 您所说的“红线”不会影响您的代码。 It's because one of the two statements is invalid, but because you are using the #IF...#Then statement in your declarations you will not throw an error. 这是因为两个语句之一无效,但是因为您在声明中使用了#IF...#Then语句,所以不会抛出错误。

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

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