关闭VBA中的每一步,然后转到另一步

时间:2016-09-28 08:53:00

标签: vba excel-vba access-vba excel

我写了一个VBA代码,它使用batch将某些文件从 A 复制到 B ,然后运行使用复制文件的Access-macros在 B 。运行宏后,VBA代码将查询结果从Access导入到Excel中。

' run the batch
    RetVal = Shell("I:\myW\k1ltios1_k1ltit31_Kopie.bat", 1)

' ============================
' run the macros in ACCESS

Dim accessApp
Set accessApp = CreateObject("Access.Application")  'define an Access object

accessApp.Visible = True 'hold Access object open

accessApp.UserControl = True
.
.
.
' <<< copy the results from Access into th eExcel files >>>
'#Enter  the valus of cells in the arrays
i = 0
ReDim marrSql(0)
 For Each cell In Worksheets("eingaben").Range("B20:B21")
    marrSql(i) = cell
    i = i + 1
    ReDim Preserve marrSql(i)
    Debug.Print marrSql(i)
Next


i = 0
ReDim marrPlace(0)
 For Each cell In Worksheets("eingaben").Range("A20:A21")
    marrPlace(i) = cell
    i = i + 1
    ReDim Preserve marrPlace(i)
Next
'# end of entering

For i = 0 To 1
'
sSQL = "SELECT * FROM [" & marrSql(i) & "];"

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim cmdCommand As ADODB.Command
.
.
.

Next

如果我运行代码它运行良好但所有窗口(批处理,Access和Excel)立即打开! 现在我的问题:如何启动批处理,如果没有错误,应该关闭它,然后在 Access 中运行宏如果没有问题,生成查询将结果复制到Excel然后关闭Access?我想确保这些步骤一个接一个地完成,否则代码会在一个或另一个步骤中查看旧结果!

0 个答案:

没有答案