我有一个项目,其基本目标是生成Excel(报告),使用VBA启动Access中的单击按钮.
此报告的内容是存储过程SQL Server数据库的结果.
错误的行:
With MeuExcel.Worksheets(4)
.QueryTables.Add connection:=rs, Destination:=.Range("A2")
End With
Run Code Online (Sandbox Code Playgroud)
我得到的是:
invalid procedure call or argument (erro '5')
Run Code Online (Sandbox Code Playgroud)
完整代码(使用Remou用户提示编辑):
Sub GeraPlanilhaDT()
Dim MeuExcel As New Excel.Application
Dim wb As New Excel.Workbook
Set MeuExcel = CreateObject("Excel.Application")
MeuExcel.Workbooks.Add
MeuExcel.Visible = True
Dim strNomeServidor, strBaseDados, strProvider, strConeccao, strStoredProcedure As String
strNomeServidor = "m98\DES;"
strBaseDados = "SGLD_POC;"
strProvider = "SQLOLEDB.1;"
strStoredProcedure = "SP_ParametrosLeads_DT"
strConeccao = "Provider=" & strProvider & "Integrated Security=SSPI;Persist Security Info=True;Data Source=" & strNomeServidor & "Initial Catalog=" & strBaseDados
Dim cnt …Run Code Online (Sandbox Code Playgroud)