![](/img/trans.png)
[英]Open a PowerPoint presentation from Excel with VBA and then set that presentation to a variable
[英]Open a PowerPoint presentation from Excel with VBA without specifying Excel file path
我正在为 PowerPoint 中的 VBA 寻找一种方法来自动识别我计算机上唯一打开的 Excel 文件并使用此 Excel 文件从中读取数据。 我想避免在我的代码中手动插入 Excel 文件路径。 可能吗?
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("PATH\FILENAME.xlsm")
xlBook.Application.Visible = False
谢谢!
请尝试下一个代码:
Sub testOpenWorkbook()
Dim Ex As Object, wb As Object
On Error Resume Next
Set Ex = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Err.Clear: On Error GoTo 0
MsgBox "There is not any Excel session open...", vbInformation, "Ups...": Exit Sub
Else
On Error GoTo 0
If Ex.Workbooks.count = 1 Then
Set wb = Ex.Workbooks(1)
Else
MsgBox "There are more Excel Workbooks open...", vbInformation, "Ups...": Exit Sub
End If
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.