VBA在Excel 2013中打开URL,64位

时间:2015-02-12 21:54:53

标签: excel vba excel-vba excel-2013

我试图通过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部分时,它会抛出一个"内存不足"即使我的系统有64GB的内存。

http://support.microsoft.com/kb/224816尝试shell执行路由对我来说不起作用,因为它返回:

http://i.imgur.com/qiAe0o0.png

有人有什么想法吗?

1 个答案:

答案 0 :(得分:1)

如果您在64位办公室中使用API​​,则可能需要将其声明为“指针安全”并使用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之间的兼容性