Excel änderungen speichern?

  • VB.NET

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von petaod.

    Excel änderungen speichern?

    In meinen Programm lese ich eine Excel datei ein,
    Öffnen:

    VB.NET-Quellcode

    1. Dim Exceldatei As New Object
    2. Exceldatei = CreateObject("excel.application")
    3. Exceldatei.application.workbooks.Open("link")
    4. Exceldatei.application.sheets(1).Select()
    5. Exceldatei.application.cells(1,1).value = "x"




    Speichern:

    VB.NET-Quellcode

    1. Excel.application.save()

    doch wenn ich das abspeichern will (und ich diese Excel-Mappe offen habe) die Frage ob ich die vorhandene Datei überschreiben will. Zwar funktioniert es wenn man "Ja" drückt, doch ich will es über eine vorhandene Datei speicher, ohne das man Excel offen hat.

    folgendes habe ich bereits probiert und es hat nicht funktioniert:

    VB.NET-Quellcode

    1. Exceldatei.save()



    VB.NET-Quellcode

    1. Exceldatei.application.save()



    VB.NET-Quellcode

    1. Exceldatei.application.workbooks.save()


    VB.NET-Quellcode

    1. Exceldatei.saveas("link")


    und das vorige auch noch mit application und workbooks(so wie oben)

    und...

    VB.NET-Quellcode

    1. ActiveWorkbook.save()


    bzw. SaveAs

    und bei allen auch mit "Savechanges:= True"



    ...doch es hat nicht funktioniert!

    Könnt ihr mir bitte helfen!

    Thx im vorhinein.

    Edit by ~blaze~:
    *Thema verschoben*

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „~blaze~“ ()

    Hallo.

    Du hast ja eine Excel-Datei geöffnet. Ergo is auch Excel offen
    Du kannst allerdings ja excel über:

    VB.NET-Quellcode

    1. Exceldatei.visible = false

    verstecken

    Das öffnen und schliessen bei mir erledige ich immer so:

    VB.NET-Quellcode

    1. Public Class frmStartBild
    2. Dim xlApp As New Excel.Application
    3. Dim xlPfadMaterial As String
    4. Dim xlMappe As Excel.Workbook
    5. Dim xlBlatt As Excel.Worksheet
    6. .
    7. .
    8. .
    9. Public Sub xlOpen(ByVal xlPfad As String, ByVal xlDateiname As String)
    10. 'Daten für die Listbox aus der Exceldatei bereitstellen
    11. xlMappe = xlApp.Workbooks.Open(xlPfad & xlDateiname)
    12. xlBlatt = CType(xlMappe.Worksheets("Datenbank"), Excel.Worksheet)
    13. xlApp.Visible = False
    14. End Sub
    15. Public Sub xlCLose(ByVal Speichern As Boolean)
    16. On Error GoTo Speicherfehler
    17. Select Case Speichern
    18. Case True
    19. If Not xlMappe Is Nothing Then xlMappe.Close(SaveChanges:=True)
    20. Case False
    21. If Not xlMappe Is Nothing Then xlMappe.Close(SaveChanges:=False)
    22. End Select
    23. If Not xlApp Is Nothing Then xlApp.Quit()
    24. Exit Sub
    25. Speicherfehler:
    26. Resume
    27. End Sub
    28. End Class


    wenn Dir das weiter hilft. Funtioniert soweit gut, ausser wenns Netzwerk mal wieder spinnt :D
    Falls da einer ne Idee zu hat...