Problem beim Schreiben in Excel-Datei (war: Hilfe zu Excel)



  • Hallo,

    Ich habe folgende Code von Forum ausprobiert und wollte ich noch was in die Excel Datei schreiben. Schreiben gibt immer Fehlermeldung.Das Problem ist die Datei schreibgeschutz geöffnet ist. Wie kann ich normal offnen?

    Variant Excel; 
         Excel = Variant::CreateObject("Excel.Application"); 
    
         Excel.OlePropertyGet("ActiveWorkBook"); 
         // Excel-Datei öffnen 
            Excel.OlePropertyGet("WorkBooks").OleFunction("Open","C:\\test.xls"); 
    
         // Sichbar machen 
         Excel.OlePropertySet("Visible",1); 
    
         Variant Sheet; 
         Sheet=Excel.OlePropertyGet("ActiveSheet"); 
         ShowMessage(Sheet.OlePropertyGet("Cells",1,1).OlePropertyGet("Value"));
    
     //meine erweiterung ist:
    Sheet.OlePropertyGet("Cells",8,1).OlePropertySet("Value",StringToOleStr("Hallo"));
    

    Kann jemand weiterhelfen?

    Gruß,
    S.Mathi 🕶

    Edit:
    Bitte aussagekräftige Überschriften wählen. Danke!



  • bei mir funktioniert dein Code einwandfrei,
    schau einfach mal, ob die Datei schreibgeschützt ist

    noch ein Tip: falls Excel schon offen ist solltest du folgendes nehmen

    try
    	{
    	Excel = GetActiveOleObject("Excel.Application");
    	}
    catch(...)
    	{
    	Excel = CreateOleObject("Excel.Application");
    	}
    


  • Linnea schrieb:

    <Edit: Zitate bitte auf das Notwendigste beschränken. Danke!>

    Hi,

    Ich habe schon nach "Datei Schreibschutz" kontrolliert. Die Datei war ohne Schreibschutz. Ich werde gleich dein Verschlag ausprobieren. :xmas2:

    Bis bald.

    Gruß
    S.Mathi



  • Hallo Linnea,

    nach der Änerung wie Sie vorgeschlagen haben, funktionert es.

    Gruß
    🙂 S.Mathi


Anmelden zum Antworten