PPT VBA如何打来excel文件读取数据?
1个回答
展开全部
假设在PPT中添加一个Textbox1. 再添加一个命令
在运行命令后,Textbox调用Excel中的指定Range的数据。
程序如下:注意需要先引用Microsoft excel 12.0 object library
Private Sub CommandButton1_Click()
Dim MyexcelApp As New Excel.Application
Dim MyexcelBook As New Excel.Workbook
Dim MyexcelSheet As New Excel.Worksheet
Pathstr = "C:\Documents and Settings\Administrator\桌面\test.xlsx"
Set MyexcelBook = MyexcelApp.Workbooks.Open(Pathstr)
Set MyexcelSheet = MyexcelBook.Worksheets(1)
MyexcelSheet.Activate
TextBox1.Text = MyexcelSheet.Range("B2").Value
MyexcelBook.Close
Set MyexcelApp = Nothing
Set MyexcelBook = Nothing
Set MyexcelSheet = Nothing
End Sub
在运行命令后,Textbox调用Excel中的指定Range的数据。
程序如下:注意需要先引用Microsoft excel 12.0 object library
Private Sub CommandButton1_Click()
Dim MyexcelApp As New Excel.Application
Dim MyexcelBook As New Excel.Workbook
Dim MyexcelSheet As New Excel.Worksheet
Pathstr = "C:\Documents and Settings\Administrator\桌面\test.xlsx"
Set MyexcelBook = MyexcelApp.Workbooks.Open(Pathstr)
Set MyexcelSheet = MyexcelBook.Worksheets(1)
MyexcelSheet.Activate
TextBox1.Text = MyexcelSheet.Range("B2").Value
MyexcelBook.Close
Set MyexcelApp = Nothing
Set MyexcelBook = Nothing
Set MyexcelSheet = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询