|
送给你一个程序,试试吧!注意要引用,程序里介绍了方法。
- 'VBE——引用——Microsoft excel 12.0 object library
- Private Sub CommandButton1_Click()
-
- Dim xlApp As Object
- Dim xlwbk As Object '定义工作薄对象
- Dim xlsht As Object '定义工作表对象
- Dim fPath As String '定义文件路径
-
- '打开对话框选择文件并获取文件路径
- With Application.FileDialog(msoFileDialogFilePicker)
- If .Show = False Then Exit Sub
- fPath = .SelectedItems(1)
- End With
-
- Set xlApp = CreateObject("Excel.Application")
- Set xlwbk = xlApp.Workbooks.Open(fPath)
- Set xlsht = xlwbk.Worksheets("入选名单")
- lrow = xlsht.Range("b1").End(xlDown).Row
-
- For i = 1 To lrow - 1
- 'Set pptSlide = ActivePresentation.Slides.Add(Index:=i + 1, Layout:=ppLayoutBlank)
- Set sld = ActivePresentation.Slides(i)
- sld.Copy
- ActiveWindow.View.Paste
-
- ActivePresentation.Slides(i + 1).Shapes("Text Box 2").TextFrame.TextRange.Text = xlsht.Cells(i + 2, 2).Value
- ActivePresentation.Slides(i + 1).Shapes("Text Box 3").TextFrame.TextRange.Text = xlsht.Cells(i + 2, 2).Value
- Next
- ActivePresentation.Slides(ActivePresentation.Slides.Count).Delete
- Set xlApp = Nothing
- Set xlwbk = Nothing
- Set xlsht = NothingEnd Sub
复制代码
学会了技术,也要报答需要的人! |
|