VBA高手进,关于PPT从EXCEl取数据问题

Dim app As Object, wb As Object
Dim xlsht As Object, xlrng As Object
Dim i, j, f As Integer
Set app = CreateObject("Excel.Application")
app.Visible = True
Set wb = app.Workbooks.Open("E:\" & "\生日提醒1.xls")
Set xlsht = wb.worksheets(1)
With wb
With xlsht
wb.worksheets("生日提醒").Activate

Shapes("TextBox 1").TextFrame.TextRange = Sheets.Application.ActiveSheet.Cells(1, 8).Value
End With
End With
我想实现PPT中的TextBox1可以从一个表格cells(1,8)取值,我做完后运行为什么报错啊,高手帮指点一下

你知道With 的含义吗,你的语句有两层嵌套,这是不可以的。建议你取消所有的with语句。

修改后如果还有错,请拷屏(弹出的错误提示窗口),并粘贴修改后的代码。追问

Shapes("TextBox 1").TextFrame.TextRange = Sheets.Application.ActiveSheet.Cells(1, 8).Value
运行时,只有这段报错,不知怎么回事

追答

仔细看你这句,你的Sheets是什么东西,机器怎么知道?

取消你的with和end with,你这句应该使用全称,大概是这样吧:
Shapes("TextBox 1").TextFrame.TextRange = wb.ActiveSheet.Cells(1, 8).Value

或者:
Shapes("TextBox 1").TextFrame.TextRange = xlsht.Cells(1, 8).Value

明白了没有,wb、xlsht才是有效的变量,在PPT里面无法识别Sheets这样的东西。

追问

运行后,还是有问题,不知道哪里有问题

追答

以下代码调试通过,保证正确运行,希望对你有所帮助:

Option Explicit
Sub xxx()
    Dim app, wb
    Set app = CreateObject("Excel.Application")
    app.Visible = True
    Set wb = app.workbooks.Open("d:\我的文档\exp\工作表.xls")
    ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange = wb.sheets(1).[t7]
    wb.Close
    app.Quit
End Sub

追问

你完美的解决了我的问题,,谢谢
但是你知道我的那条报错是怎么回事吗?

追答

你对比语句差异就明白了

温馨提示:答案为网友推荐,仅供参考
相似回答