最新WPS办公软件学习教程_免费企业办公软件下载_金山WPS Office官网论坛

 找回密码
 
查看: 506|回复: 0

[VBA/VBS教程] 求助:2013版excel的VBA 放到WPS中运行,出现“自动化错误”

[复制链接]

1

主题

1

听众

4

积分

LV.1

Rank: 1

该用户从未签到

金币
3
威望
4
帖子
1
精华
0
发表于 2017-7-31 10:57 |显示全部楼层
分享到: 新浪微博 腾讯微博
各位大神:
5 R; `5 R  Q; C4 l1 V4 a6 h    求助一下,我在2013版excel运行以下VBA代码正常,但是放到WPS中却显示“自动化错误”,请各位大神帮忙看看!
) m: H/ B, Z; `5 X代码如下:1 X$ |" O$ w, P3 |2 V) l, S
Sub 转换()
- A" j2 F, A7 y' D$ a4 H) nDim cnn
4 J9 e9 I5 d% x  H; o: {Dim rsMst1 As ADODB.Recordset0 ~9 q, \! b, @4 k% P" G% G( J
Dim sql As String
* j; {9 b% S# X) J; _& |# y! Q3 IDim i, m, brr, crr, row
* y0 m. G. ~. g* T9 H' P" x9 r% b2 z2 F6 j
Application.ScreenUpdating = False
7 ?) g1 ]: _' c* j Application.DisplayAlerts = False& @3 b" `- ~* P5 {
7 A8 j5 v. ~' a7 e+ J- u3 ~( |
Sheet6.Range("ah2").Resize(65535, 2).ClearContents
, d3 k3 W6 M3 OSheet7.Range("a2").Resize(65535, 9).ClearContents
$ P/ L# m" \4 B, Y# F6 |" c) _9 \5 ~/ S. @. x# I7 d
Sheet10.Range("A4").Select# Z# d. L1 i/ Y8 F% L
Range(Selection, Selection.End(xlDown)).Select
' x* }/ B7 Y0 h  b7 A3 pSelection.EntireRow.Delete
; F' ]4 s5 u/ `4 i3 ]& c1 |  Set cnn = CreateObject("ADODB.CONNECTION")
+ V. `5 ]( W5 t) l! c Application.ScreenUpdating = False: V$ c$ g5 V: B6 X6 g. [
  cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName   ; ?2 [" H3 l6 f  f

* e# h- e% i/ z, R: k9 _sql = " select 制单号2,sum(印花送货),sum(印花回货),sum(当天上货数),sum([DC区WIP]),sum(待印花WIP),sum(印花总送货),sum(印花总回货),sum(累计上货数) " _
5 d: {. I; L. w0 q& `5 D- L, G& "from [实时生产信息数据$] a " _2 ^1 ?7 t) b9 S3 `* D
& "where a.印花总送货<>0 " _2 X3 h( I( _+ d
& "and (总WIP<>0 or 总WIP=0 and 当天上货数<>0)" _3 I. w) A" C) M
& "group by 制单号2"$ b- w& }/ [6 l
8 Z: {( H: H2 ]/ }& I, l! A
Set rsMst1 = cnn.Execute(sql)) P; u5 d" D) A% t2 G' k0 @/ D
   Arr = rsMst1.GetRows
) m4 C) e/ y( B0 H' ersMst1.Close
, ^# ?6 {! S& g; B1 q cnn.Close% M. v- C8 ]1 _9 Z4 w7 q2 l
  Set cnn = Nothing
# P6 r1 c" W3 x0 t1 {2 P   Sheet7.Range("A2").Resize(UBound(Arr, 2) + 1, 10) = Application.Transpose(Arr). \( E) e' t" f( A
Application.ScreenUpdating = True4 I' Z% x# X+ w1 y0 G3 z& F
Application.DisplayAlerts = True6 f( A1 g/ }- R4 _
    End Sub
) r5 ?" x/ I9 T  D. J7 B5 ^
7 s, a% s* B+ V1 r# [! z$ }; n9 G目前WPS中引用的工具如下:$ D/ q+ U, b" N3 D, z4 f
  Visual Basic For Applications
5 l  y4 j1 @% B- }, F, i" y8 ~  Kingsoft ET 2.0 Objects Library
8 k/ t) w0 G! y1 V) x OLE  Automation1 ]# ]! u4 p5 K' t* ?' E+ Q* c; x
Microsoft Froms 2.0 Objects Library8 l- @- d& f0 ^3 f9 N
Microsoft ActiveX data objects 6.1. X; t" j$ L$ {% Z$ U* Y1 S
Microsoft Offices 15.0 Objects Library& k; ^! Z7 @9 ^+ n4 A
, l  o0 V- O5 V8 R5 c/ m" U
WPS中运行显示“-2147467259(80004005) 自动化(Automation)错误”. {$ f5 g+ x5 b% u7 ]3 C
/ X* {- w6 H3 C
*滑动验证:
您需要登录后才可以回帖 登录 | 更多账号登录:

快速回帖:

fastpost

WPS论坛更新日志|WPS Office官方论坛     

GMT+8, 2017-12-12 22:07

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部