Dim exApp As Excel.Application
Dim i, k As Integer
Private Sub Command1_Click()
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) >= 1 Then
exApp.Workbooks.Open CommonDialog1.FileName
For k = 1 To 5
Range(Cells(k, 1), Cells(k, 1)) = "aa"
Range(Cells(k, 7), Cells(k, 7)) = "aa"
Range(Cells(k, 8), Cells(k, 8)) = "aa"
Range(Cells(k, 9), Cells(k, 9)) = "aa"
Next
exApp.ActiveWorkbook.Save
exApp.ActiveWorkbook.Close
End If
exApp.Quit
Set exApp = Nothing
Timer1.Enabled = True
Timer1.Interval = 3000
End SubPrivate Sub Command2_Click()
End
End SubPrivate Sub Form_Load()
Set exApp = New Excel.Application
End SubPrivate Sub Timer1_Timer()
k = k + 1
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) >= 1 Then
exApp.Workbooks.Open CommonDialog1.FileName
Range(Cells(k, 6), Cells(k, 6)) = k
Range(Cells(k, 7), Cells(k, 7)) = k
Range(Cells(k, 8), Cells(k, 8)) = k
Range(Cells(k, 9), Cells(k, 9)) = k
exApp.ActiveWorkbook.Save
exApp.ActiveWorkbook.Close
End If
exApp.Quit
Set exApp = Nothing
End Sub
当程序运行进入Private Sub Timer1_Timer()这个里面时,再次打开CommonDialog1.FileName就出现实时错误'91',对象变量或 With 块变量没有设置(错误 91),小弟不才还请各位高手指点!
Dim i, k As Integer
Private Sub Command1_Click()
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) >= 1 Then
exApp.Workbooks.Open CommonDialog1.FileName
For k = 1 To 5
Range(Cells(k, 1), Cells(k, 1)) = "aa"
Range(Cells(k, 7), Cells(k, 7)) = "aa"
Range(Cells(k, 8), Cells(k, 8)) = "aa"
Range(Cells(k, 9), Cells(k, 9)) = "aa"
Next
exApp.ActiveWorkbook.Save
exApp.ActiveWorkbook.Close
End If
exApp.Quit
Set exApp = Nothing
Timer1.Enabled = True
Timer1.Interval = 3000
End SubPrivate Sub Command2_Click()
End
End SubPrivate Sub Form_Load()
Set exApp = New Excel.Application
End SubPrivate Sub Timer1_Timer()
k = k + 1
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) >= 1 Then
exApp.Workbooks.Open CommonDialog1.FileName
Range(Cells(k, 6), Cells(k, 6)) = k
Range(Cells(k, 7), Cells(k, 7)) = k
Range(Cells(k, 8), Cells(k, 8)) = k
Range(Cells(k, 9), Cells(k, 9)) = k
exApp.ActiveWorkbook.Save
exApp.ActiveWorkbook.Close
End If
exApp.Quit
Set exApp = Nothing
End Sub
当程序运行进入Private Sub Timer1_Timer()这个里面时,再次打开CommonDialog1.FileName就出现实时错误'91',对象变量或 With 块变量没有设置(错误 91),小弟不才还请各位高手指点!
解决方案 »
- 鼠标点击vb窗体的标题栏触发什么事件(补偿分数的,其他勿扰)
- 【急】Windows7 下面用VBA中的GetObject()方法打开一个.xls命名的CSV文件返回432错误!!!!
- 如何在MSHFlexGrid控件上选中一行记录后,点击右键弹出一个菜单。又如何往这个菜单里添加删除该记录行的代码。
- 还有几个月就要当爸爸,和大家一起分享。大家也帮忙我儿子想一个好名字。
- 各位,谁开发过专家系统软件?给我说说或赐些资料,急!
- 怎么让FLEXGRID的某一行显示不同的颜色??
- winsock的GetData是不是只能接受4k的数据?怪事!!!
- Shell "rundll32.exe C:\WINDOWS\SYSTEM\MSHTML.DLL,PrintHTML " & Text1.Text, vbNormalFocus 能打印一张网页吗,原理是什么?谢谢!
- 如何用vb制作自定义报表程序
- VB SQL环境下 实现图书借阅成功,图书库存数量减一
- xp与2000 WM_SYSCOMMAND不同吗
- 求助,我现在需要做直接从COM口打印,打印机是TM U220B,用VB.60 VB.net C#都行,请问有高手做过这方面的没有!!谢谢
改为这样:Dim exApp As Excel.Application
Dim i, k As Integer
Private Sub Command1_Click()
Set exApp = Nothing '我增加的
Set exApp = New Excel.Application '我增加的
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) >= 1 Then
If Not IIf(Dir(FileName) <> "", True, False) Then Exit Sub '我增加的
exApp.Workbooks.Open CommonDialog1.FileName
For k = 1 To 5
Range(Cells(k, 1), Cells(k, 1)) = "aa"
Range(Cells(k, 7), Cells(k, 7)) = "aa"
Range(Cells(k, 8), Cells(k, 8)) = "aa"
Range(Cells(k, 9), Cells(k, 9)) = "aa"
Next
exApp.ActiveWorkbook.Save
exApp.ActiveWorkbook.Close
End If
exApp.Quit
Set exApp = Nothing
Timer1.Enabled = True
Timer1.Interval = 3000
End SubPrivate Sub Command2_Click()
End
End SubPrivate Sub Form_Load()
Set exApp = New Excel.Application
End SubPrivate Sub Timer1_Timer()
Set exApp = Nothing '我增加的
Set exApp = New Excel.Application '我增加的
k = k + 1
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) >= 1 Then
If Not IIf(Dir(FileName) <> "", True, False) Then Exit Sub '我增加的
exApp.Workbooks.Open CommonDialog1.FileName
Range(Cells(k, 6), Cells(k, 6)) = k
Range(Cells(k, 7), Cells(k, 7)) = k
Range(Cells(k, 8), Cells(k, 8)) = k
Range(Cells(k, 9), Cells(k, 9)) = k
exApp.ActiveWorkbook.Save
exApp.ActiveWorkbook.Close
End If
exApp.Quit
Set exApp = Nothing
End Sub
我刚才运行了一下,出了点问题
If Not IIf(Dir(FileName) <> "", True, False) Then Exit Sub '我增加的 说此处类型不匹配
能帮我再看下吗?
改为 If Not IIf(Dir(CommonDialog1.FileName) <> "", True, False) Then Exit Sub