ich habe einen kleinen Code in VB der nur beim ersten Mal funktioniert:
Global xlApp As Excel.Application
Global xlwrkbk1 As Excel.Workbook
Global xlsheet1 As Excel.Worksheet
Global strfilename As String
Global MyReg As String
Sub Excel()
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlwrkbk1 = xlApp.Workbooks.Open(strfilename)
Set xlsheet = xlApp.Application.ActiveWorkbook.Sheets(MyReg)
xlApp.Selection.QueryTable.Refresh BackgroundQuery:=False
xlApp.Application.ActiveWorkbook.Save
xlApp.Application.ActiveWorkbook.Close
xlApp.Application.Quit
xlApp.Quit
Set xlApp = Nothing
Set xlwrkbk1 = Nothing
Set xlsheet = Nothing
End Sub
MyReg = Tabnamestrfilename = wo sich das File befindet incl. Filname (z.B. c:\test.xls)
Mit Call Excel spreche ich es an und beide Variablen (Myreg und strfilename) haben sind richtig _ "befüllt". Beim ersten durchlauf wird das Sheet - nennen wir es Test1.xls) aktualisiert. Nach End
Sub springe ich zurück, "befülle" wieder meine Variablen und springe mit call Excel und dann _
kommt bei:
xlApp.Selection.QueryTable.Refresh BackgroundQuery:=False
die Fehlermeldung: Laufzeitfehler 1004
Weiß jemand was ich hier vergessen habe oder falsch mache?
Vielen Dank!