当前位置: 首页 > article >正文

3704对象关闭时_对象关闭时,不允许操作,运行时错误3704

Sub 合并数据()

Dim cnn As Object, rs As Object

Dim SQL$, MyFile$, s$, m&, n&, t$, i%, z$, v%

With Application.FileDialog(msoFileDialogFolderPicker)

.InitialFileName = ThisWorkbook.Path & ""

If .Show = False Then Exit Sub

MyPath = .SelectedItems(1) & ""

End With

Dim msg As String, nsg As String, BBB As String

Application.ScreenUpdating = False

Set cnn = CreateObject("ADODB.Connection")

Set cat = CreateObject("ADOX.Catalog")

Cells.ClearContents

MyFile = Dir(MyPath & "*.xlsx")

On Error Resume Next

Do While MyFile <> ""

If MyFile <> ThisWorkbook.Name Then

n = n + 1

If n = 1 Then

'cnn.Open "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & MyPath & MyFile

cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & MyPath & MyFile & "';Extended Properties='Excel 12.0 Xml';"

Else

t = "[Excel 12.0;Database=" & MyPath & MyFile & "]."

End If

cat.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & MyPath & MyFile & "';Extended Properties='Excel 12.0 Xml';" '"Provider=Microsoft.jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & MyPath & MyFile

For Each tb1 In cat.Tables

If tb1.Type = "TABLE" Then

z = ""

z = tb1.Columns(0).Name

If Left$(z, 1) <> "F" Then

s = Replace(tb1.Name, "'", "")

If Right(s, 1) = "$" Then

v = v + 1

If v = 1 Then

Set rs = cnn.Execute("[" & s & "]")

For i = 1 To rs.Fields.Count

Cells(1, i) = rs.Fields(i - 1).Name

Next

End If

m = m + 1

If m > 49 Then

Range("a" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(SQL)

m = 1

SQL = ""

End If

If Len(SQL) Then SQL = SQL & " union all "

SQL = SQL & "select * from " & t & "[" & s & "] "

End If

End If

End If

Next

End If

MyFile = Dir()

Loop

On Error GoTo 0

If Len(SQL) Then Range("a" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(SQL)

cnn.Close

Set cnn = Nothing

Set cat = Nothing

Set tb1 = Nothing

Application.ScreenUpdating = True

End Sub

http://www.lryc.cn/news/2419717.html

相关文章:

  • DDD究竟是什么
  • 电子爱好者DIY篇
  • File类的createNewFile()方法和createTempFile()方法
  • 如何复制一个文件
  • golang反射简介
  • 电脑系统时间同步更新时提示“RPC服务器不可用”解决办法
  • PostgreSQL数据库安装教程
  • 杀死excel所有进程
  • 苹果电脑怎么切换输入法_高顿:CPA考试技巧:巧用搜狗输入法“v”模式,非常实用!...
  • 解惑:Redis的HSCAN命令中COUNT参数的失效场景
  • JINK/SWD找不到内核,故障汇总
  • 调试编译错误信息总结
  • oracle 如何实现excel的正态分布函数normdist
  • CAPLE实现CAN路由的自动化测试
  • 应用层与驱动层通信DeviceIoControl
  • GoYouBBS: 基于Go语言构建的强大论坛系统
  • 渗透测试工程师——第一部分 信息扫描实验系列 001主机存活性探测实验
  • Android布局基础知识:wrap_content,match_parent,layout_weight
  • 树莓派安装MJPG-streamer
  • GALGAME文字提取agth 特殊码大全(特殊码表)和使用方法
  • delphi中使用MSWINSCK.OCX控件
  • 私库如何区分正式和测试环境独立的库
  • md5值是什么意思_详解:PER?霍林格效率值?这个最火的高阶数据究竟是什么意思?...
  • 正在载入中......loading页面的几种方法
  • c++求矩阵的秩_Matlab:矩阵的秩,简化梯形矩阵和线性方程组
  • 【C语言】:static和extern的详细介绍和使用
  • softcore -- CPU rasterization
  • xp序列号大全可通过正版验证的XP序列号发布
  • SolrIK分词器-简单介绍与安装
  • MouseArea组件和MouseEvent事件在Qt中是经常使用的重要组件和事件。本文将详细介绍MouseArea组件和MouseEvent事件的用法,并提供...