Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Daten zwischen zwei Excel-Tabelle per VBA-Modul in Access austauschen

Empfohlene Antworten

Veröffentlicht

Hallo,

ich habe wieder mal ein Problem.

Ich habe ein Programm geschrieben, dass einen Bericht als eine Excel-Tabelle exportiert. Diese Tabelle soll jetzt die Daten an eine weitere Tabelle weitergeben und das funktioniert nicht. Wie stelle ich das an?

Mein Code:


Dim xlAnw1 As Excel.Application

Dim xlAnw2 As Excel.Application

Dim xlBuch1 As Excel.Workbook

Dim xlBuch2 As Excel.Workbook

Dim xlArbBlatt1 As Excel.Worksheet

Dim xlArbBlatt2 As Excel.Worksheet


Sub Exportieren()

Dim i, j, y, z As Integer


On Error GoTo ErrorHandler

Set xlAnw1 = GetObject(, "Excel.Application")

Set xlAnw2 = GetObject(, "Excel.Application")

On Error GoTo 0


'Exportieren des Reportes in eine lokale temporäre Excel-Datei

DoCmd.OutputTo acOutputReport, "EntladungContainerIst", acFormatXLS, "J:\Access\temp.xls", 0


Set xlBuch1 = xlAnw1.Workbooks.Open("J:\Access\temp.xls", , False)

Set xlArbBlatt1 = xlBuch1.Worksheets(1)


Set xlBuch2 = xlAnw2.Workbooks.Open("J:\Access\standard.xls", , False)

Set xlArbBlatt2 = xlBuch2.Worksheets(2)


xlArbBlatt1.Activate

xlArbBlatt2.Activate


y = xlArbBlatt1.UsedRange.Columns.Count

z = xlArbBlatt1.UsedRange.Rows.Count


'Kopieren der Daten aus der temporären Datei in die Standardtabelle

For i = 1 To y

    For j = 1 To z

          xlAnw2.Cells(j, i) = xlAnw1.Cells(j, i)

    Next j

Next i




'Schließen der beiden Dateien

xlBuch1.Save

xlBuch1.Close

xlBuch2.Save

xlBuch2.Close

xlAnw1.Quit

xlAnw2.Quit


'Löschen der temporären Datei

Kill "J:\Access\temp.xls"


Exit Sub


ErrorHandler:

    Set xlAnw1 = CreateObject("Excel.Application")

    Set xlAnw2 = CreateObject("Excel.Application")

    Resume Next

End Sub

Wenn er nun in das Innere der For-Schleifen gelangt, kommt diese Fehlermeldung:

Laufzeitfehler '1004'

Anwendungs- oder objektdefinierter Fehler.

Also, was mache ich falsch?

Gruß

JayN

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.