注册 登录
编程论坛 VB6论坛

VB操作已经打开着的EXCEL

kaij1220 发布于 2013-08-28 17:04, 744 次点击
VB操作已经打开着的EXCEL
我想在任意打开的EXCEL中插入数值
Private Sub Command1_Click()
Dim i As Long
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then Exit Sub '没有打开
Set xlBook = xlApp.ActiveWorkbook  '打开的EXCEL文件
For i = 0 To 10
  xlApp.ActiveCell.Offset(i) = i
Next i
xlBook.Save
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
这样的代码
Set xlApp = GetObject(, "Excel.Application")出现错误代码429 求解
2 回复
#2
风吹过b2013-08-28 17:15
你的代码,在我的机子上没问题,因为我的代码也是这一模一样的。

    If Option1.Value Then
        Set excel1 = GetObject(, "Excel.Application")
        '是否有错误
        If Err.Number <> 0 Then
            '错误,提示,结束过程
            MsgBox "没有运行 Excel。请打开需要清理对象的文件后重新刷新。", vbCritical, "错误"
            Exit Sub
        End If
    Else
        Set excel1 = GetObject(, "et.Application")
        '是否有错误
        If Err.Number <> 0 Then
            '错误,提示,结束过程
            MsgBox "没有运行 WPS 表格(Et)。请打开需清理对象的文件后重新刷新。", vbCritical, "错误"
            Exit Sub
        End If        
    End If
#3
kaij12202013-08-28 17:38
回复 2楼 风吹过b
奇了怪了
1