Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PowerPoint中使用VBA寻址打开的Excel文件时出错_Excel_Vba_Powerpoint - Fatal编程技术网

在PowerPoint中使用VBA寻址打开的Excel文件时出错

在PowerPoint中使用VBA寻址打开的Excel文件时出错,excel,vba,powerpoint,Excel,Vba,Powerpoint,我正在尝试在PowerPoint中使用vba宏来打开和检索Excel文件中的信息。 Excel文件保存在共享点中,我可以打开它。但是,当我想引用工作簿以从其单元格中检索信息时,它会给出以下错误:Automation error invalid syntax-2147221020(800401e4) 以下是我目前掌握的代码: Sub test() Dim wb As Excel.Workbook Dim ws As Excel.Worksheet Application.D

我正在尝试在PowerPoint中使用vba宏来打开和检索Excel文件中的信息。 Excel文件保存在共享点中,我可以打开它。但是,当我想引用工作簿以从其单元格中检索信息时,它会给出以下错误:
Automation error invalid syntax-2147221020(800401e4)

以下是我目前掌握的代码:

Sub test()
    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet
    Application.DisplayAlerts = False         

    'open excel from sharedpoint
    ActivePresentation.FollowHyperlink _
      Address:="http://teams.blabla.com/Shared%20Documents/Overview_NPD_Projects.xlsm", _
      NewWindow:=True, AddHistory:=True

    Set wb = GetObject("http://teams.blabla.com/Shared Documents/Overview_NPD_Projects.xlsm")
    ' this does not work even when I change it to "Shared%20Documents"

    Set ws = wb.Worksheets("Project List")

    auxvariable = ws.Range("B2").Value

End Sub
有趣的是,如果在运行宏之前尝试将excel文件手动保存到桌面,并将路径更改为:

Set wb = GetObject("C:\Users\Filipe.freitas\Desktop\Overview_NPD_Projects.xlsm")
我会将文件保存到桌面并使用正确的路径,但在执行此操作之前,我需要参考excel文件。 任何帮助都将不胜感激

你试过了吗

Dim xlapp as object
xlapp = createobject("Excel.Application")
set wb = xlapp.workbooks.open("thefilenamewhereyousavethedownload")

尝试设置wb=GetObject(,“Excel.Application”).workbook(“Overview\u NPD\u Projects.xlsm”)?它工作得非常好!非常感谢!大卫,不幸的是代码几天后就停止工作了。。。现在它总是在您建议的行中给我以下错误:“运行时错误'9'。下标超出范围”。即使excel名称是正确的。。。知道为什么会发生这种情况吗?我想只有当文件已经打开时,这一行才会起作用。如果文件未打开,则该操作将不起作用。