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.

Objekt unterstützt diese Eigenschaft oder Methode nicht

Empfohlene Antworten

Veröffentlicht

Hallo,

mittels VB6 versuche ich Daten aus einer Excel Datei zu lesen, das öffnen und kopieren der Datei klappt, was nicht klappt ist das lesen.

Bei der Zeile

Sheet1.Cells(1, 1) = "Hallo"

bekomme ich die Fehlermeldung

"Objekt unterstützt diese Eigenschaft oder Methode nicht"

woran kann das liegen?

Matthias

Original geschrieben von matthiasr

Sheet1.Cells(1, 1) = "Hallo"

dir ist aber klar dass man damit was in eine Zelle schreibt und nicht liest...

schon mit msgbox Sheet1.Cells(1, 1) versucht?

Sorry, ja, dennoch bekomme ich die Fehlermeldung

dann sei so gut und poste doch etwas mehr aus deinem Coding...

Quellcode:

Private Sheet1 As Object

Private Sub Command1_Click()

Dim oExcel As Object

Set oExcel = CreateObject("excel.Application")

'appl. öffnen

Set Sheet1=oExcel.Workbooks.Open("C:\test1.xls")

End Sub

Private Sub Command3_Click()

Sheet1.Cells(1, 1) = "Hallo"

End Sub

Original geschrieben von matthiasr

Quellcode:

Private Sheet1 As Object

Private Sub Command1_Click()

Dim oExcel As Object

Set oExcel = CreateObject("excel.Application")

'appl. öffnen

Set Sheet1=oExcel.Workbooks.Open("C:\test1.xls")

End Sub

Private Sub Command3_Click()

Sheet1.Cells(1, 1) = "Hallo"

End Sub

wenn du ein Objekt in einer Sub erstellst würde ich nicht darauf bauen dass du von einer anderen Sub aus darauf zugreifen kannst... leg doch die Variablen außerhalb (also als Globale Variablen) an ;) also praktisch da wo du das Sheet1 deklariert hast...

Ich habs auch schon so probiert

Quellcode:

Private Sheet1 As Object

Private Sub Command1_Click()

Dim oExcel As Object

Set oExcel = CreateObject("excel.Application")

'appl. öffnen

Set Sheet1=oExcel.Workbooks.Open("C:\test1.xls")

Sheet1.Cells(1, 1) = "Hallo"

End Sub

mit dem selben Ergebnis. Ich denke das sollte auch Deinen Vorschlag erfüllen, wenn ich mich nicht täusche.

Dennoch ein guter Grundsätzlicher Tipp.

Matthias


Public oExl As Object

Private Sub OpenExlWS(ByVal sWSName As String, ByVal sTabName As String)
Dim A As Variant
Dim Zeile As Long, Spalte As Integer

Set oExl = CreateObject("excel.Application")

' Workbook öffnen
On Error Resume Next
oExl.WorkBooks.Open sWSName
If Err > 0 Then
MsgBox "Exceldatei konnte nicht gefunden oder geöffnet werden.", _
vbExclamation, "Dateifehler"
Exit Sub
End If

On Error GoTo 0

' Tabelle selektieren:
oExl.ActiveWorkbook.Sheets(sTabName).Select

' Zelle lesen
A = oExl.ActiveSheet.Cells(1, 1).Value

' Zelle schreiben
oExl.ActiveSheet.Cells(1, 1).Value = "Test"

oExl.Quit
Set oExl = Nothing
End Sub


Private Sub Form_Load()
Call OpenExlWS("C:\TEST.xls", "Tabelle2")
End Sub
[/php]

tested ;)

edit:

die Zeile und Spalte kannst du dann noch Variabel machen... im Bsp. sind die fest (die variablen oben sind also unnötig...)

Heute Abend komme ich zum Testen und teile Dir mein Ergebniss mit.

Hallo,

ich habe einfach ActiveSheet eingesetzt und schon läuft es, ich hoffe das ich damit nicht irgendwas völlig falsch obwohl es geht.

oExl.ActiveSheet.Cells(1, 1).Value = "Test"

Danke für die Hilfe

Matthias

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.