|
终于知道是哪的问题了,xlUp是一个Excel定义的常量,PowerPoint中没有这个常量定义,所以需要先 Const xlUp As Long = -4162
复制代码
定义出来才能正常运行。或者直接用数值应该也行。
下面的代码亲测有效
- Option Explicit
- Sub cc()
- '以下代码提醒使用者先清空原有幻灯片
- '====================================================================================
- If ActivePresentation.Slides.Count <> 1 Then
- MsgBox ("请先清空除封面以外的所有幻灯片!!!")
- Exit Sub
- End If
- '以下代码导入excel数据源
- '====================================================================================
- Dim xlApp As Object
- Dim xlWBK As Object '定义工作薄对象
- Dim xlSht As Object '定义工作表对象
- Dim fPath As String '定义筹号文件路径
- Dim lastRow As Integer '定义最后一个筹号所在的行
- Dim arrID
- Const xlUp As Long = -4162
- '打开对话框选择文件并获取文件路径
- 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.Sheets("筹号")
- 'arrID = xlSht.Range("A2:A17") '用这句代码没问题,但换成下面的代码就出错了
- lastRow = xlSht.Cells(xlSht.Rows.Count, "A").End(xlUp).Row
- arrID = xlSht.Range("A2:A" & lastRow)
- xlWBK.Close False
- '释放对象
- Set xlApp = Nothing
- Set xlWBK = Nothing
- Set xlSht = Nothing
- End Sub
复制代码 |
|