回复 2楼 ZHRXJR
能不能帮我看一下这下边的代码问题出在哪里 ,导入不了数据 说是Set exlapp = CreateObject("excel.application")这一句有问题
谢谢大神
Private Sub Command2_Click()
CommonDialog1.DialogTitle = "载入调出点数据"
CommonDialog1.Filter = "Excel 文件(*.xls)|*.xls"
CommonDialog1.CancelError = False
CommonDialog1.ShowOpen
With MSFlexGrid1
Dim rw, cl As Integer
Dim exlapp As Object
Set exlapp = CreateObject("excel.application")
On Error GoTo 100
If Dir(Parh + CommonDialog1.FileName) <> "" Then
exlapp.Workbooks.Open (CommonDialog1.FileName)
MSFlexGrid1.Rows = exlapp.Sheets(1).UsedRange.Rows.Count
MSFlexGrid1.Cols = exlapp.Sheets(1).UsedRange.Columns.Count
For rw = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.TextMatrix(rw, 0) = rw - 1
MSFlexGrid1.RowHeight(rw) = 350
Next rw
MSFlexGrid1.RowHeight(0) = 350
MSFlexGrid1.ColAlignment(0) = 4
For cl = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.TextMatrix(0, cl) = "调出点" & cl
MSFlexGrid1.ColWidth(cl) = 1300
MSFlexGrid1.ColAlignment(cl) = 4
Next cl
MSFlexGrid1.ColWidth(0) = 1300
For rw = 1 To MSFlexGrid1.Rows - 1
For cl = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.TextMatrix(rw, cl) = exlapp.Sheets(1).Cells(rw + 1, cl + 1)
Next cl
Next rw
exlapp.Quit
Text1.Left = MSFlexGrid1.Left + MSFlexGrid1.ColPos(1) + 50
Text1.Top = MSFlexGrid1.Top + MSFlexGrid1.RowPos(1) + 50
Text1 = MSFlexGrid1.TextMatrix(1, 1)
Text1.SetFocus
Exit Sub
ElseIf Dir(Path + CommonDialog1.FileName) = "" Then
MsgBox "请确认文件是否存在!", 0 + 48, "文件错误"
Exit Sub
End If
100:
If Err.Number <> 32755 Then
MsgBox "数据载入已取消!", 48, "警告"
End If
End With
End Sub