VBA 在 Excel 2013 中打开 URL,64 位

VBA Open URL's in Excel 2013, 64bit

我正在尝试通过 vba 打开链接,但我遇到了很多问题,这是我之前使用的:

Sub OpenUrl()

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
        .DisplayAlerts = False
    End With

    Dim lSuccess As Long
    Dim LastRow as Long

    LastRow = Range("A65536").End(xlUp).Row

    For Cell = LastRow To 1 Step -1
        'lSuccess = ShellExecute(0, "Open", Range("D" & Cell).Value)
        ThisWorkbook.FollowHyperlink (Range("D" & Cell).Value)
    Next Cell

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
    End With

End Sub

然而,当它到达 ThisWorkbook.Followhyperlink 部分时,它会抛出一个 "Out of memory",即使我的系统有 64GB 内存。

尝试 shell execute route from: http://support.microsoft.com/kb/224816 对我也不起作用,因为它 returns:

有人有什么想法吗?

如果您在 64 位办公室中使用 API,那么您可能需要将其声明为 'pointer safe' 并使用 VBA7 LongPtr 类型。您可以使用条件编译来使用 VBA7 Win64 常量测试环境:

#If Win64 Then
    Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA"( _
    ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
    ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As LongPtr) 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

查看 this MSDN article 关于 32 位和 64 位 Office 与 VBA 之间的兼容性的详细信息