English
Source / code snippets

Blattschutz Remove Excel Ocx Ocxmethod Sheets Tabellenblatt Unprotect Workbooks

 
Stephan Sonneborn (06.02.11)

...
CompileMarkSeparation
'*-------------------------------------------------------------------------------------------------*
'* Exceldatei öffnen                                                                               *
'*-------------------------------------------------------------------------------------------------*

PROC OpenExcelFile

    '*-------------------------------------------------------------------------------------------------*
    PARAMETERS File$
    '*-------------------------------------------------------------------------------------------------*
    DECLARE    UsedRange&, Rows&
    '*-------------------------------------------------------------------------------------------------*

    IF FILEEXISTS(File$)

        'Excel unsichtbar starten:
        Excel&      = ocxCREATE("Excel.Application")
        Workbooks&  = ocxGet(Excel&,"Workbooks")
        ExcelWnd&   = ocxGet(Excel&,"Hwnd")
        ocxPut(Excel&,"DisplayAlerts",1)
        ocxPut(Excel&,"Visible"      ,1)
        '*-------------------------------------------------------------------------------------------------*
        'Excel-Datei öffnen:
        ExcelBook&  = ocxMethod(Workbooks&,"Open"  , File$)
        ExcelSheet& = ocxGet(ExcelBook&,   "Sheets", ExcelSheet$)
        ocxMethod(ExcelSheet&,  "Unprotect")
        Range&      = ocxGet(ExcelSheet&,  "Range", "A1")
        UsedRange&  = ocxGet(ExcelSheet&,  "UsedRange")
        Rows&       = ocxGet(UsedRange&,   "Rows")
        ExcelSheetLines& = ocxGet(Rows&,        "Count")
        LastBOMPos& = INT((ExcelSheetLines& - 19)/4)

    ELSE

        ExcelWnd& = 0

    ENDIF

    '*-------------------------------------------------------------------------------------------------*
    'Rückgabewert:
    RETURN ExcelWnd&
    '*-------------------------------------------------------------------------------------------------*

ENDPROC

'*-------------------------------------------------------------
------------------------------*

 
02/07/11  
 




Stephan
Sonneborn
then here another slightly More.
but Please mind: the only Codeschnippsel, so How you're on my own not walk. there must another slightly Program drumrum.
CompileMarkSeparation
'Codesnipset mit der OCX-Erweiterung von Uwe "Pascal" Niemeier
'***************************************************************************************************
' Header-Dateien laden                                                                             *
'***************************************************************************************************
 $H WINDOWS.PH
 $H OCX3a.PH
 $H COMMCTRL.PH
'***************************************************************************************************
'***************************************************************************************************
' Include-Dateien laden                                                                            *
'***************************************************************************************************
 $I OCX3a.INC
 $I USER.INC
'***************************************************************************************************
'***************************************************************************************************
'* Globale Variablen                                                                               *
'***************************************************************************************************
DECLARE Excel&, Workbooks&, ExcelWnd&, ExcelBook&, ExcelSheet&, ExcelSheet$, ExcelSheetLines&
DECLARE Range&
*-------------------------------------------------------------------------------------------------*
'* Exceldatei öffnen                                                                               *
'*-------------------------------------------------------------------------------------------------*

PROC OpenExcelFile

    '*-------------------------------------------------------------------------------------------------*
    PARAMETERS File$
    '*-------------------------------------------------------------------------------------------------*
    DECLARE    UsedRange&, Rows&, Cell$
    '*-------------------------------------------------------------------------------------------------*

    IF FILEEXISTS(File$)

        'Excel unsichtbar starten:
        Excel&      = ocxCREATE("Excel.Application")
        Workbooks&  = ocxGet(Excel&,"Workbooks")
        ExcelWnd&   = ocxGet(Excel&,"Hwnd")
        ocxPut(Excel&,"DisplayAlerts",1)
        ocxPut(Excel&,"Visible"      ,0)
        '*-------------------------------------------------------------------------------------------------*
        'Excel-Datei öffnen:
        ExcelBook&  = ocxMethod(Workbooks&, "Open"  , File$)
        ExcelSheet& = ocxGet(ExcelBook&,    "Sheets", ExcelSheet$)
        ocxMethod(ExcelSheet&,"Unprotect")
        Range&      = ocxGet(ExcelSheet&,   "Range", "A1")
        UsedRange&  = ocxGet(ExcelSheet&,   "UsedRange")
        Rows&       = ocxGet(UsedRange&,    "Rows")
        ExcelSheetLines& = ocxGet(Rows&,    "Count")
        Cell$       = "A" + STR$(ExcelSheetLines& - 3)
        Range&      = ocxGet(ExcelSheet&, "Range", Cell$)
        LastBOMPos& = VAL(ocxGET(Range&, "Text"))

    ELSE

        ExcelWnd& = 0

    ENDIF

    '*-------------------------------------------------------------------------------------------------*
    'Rückgabewert:
    RETURN ExcelWnd&
    '*-------------------------------------------------------------------------------------------------*

ENDPROC

'*-------------------------------------------------------------------------------------------------*
'*-------------------------------------------------------------------------------------------------*
'* MS Excel schließen                                                                              *
'*-------------------------------------------------------------------------------------------------*

PROC CloseExcelFile

    '*-------------------------------------------------------------------------------------------------*
    'Excel schließen:
    ocxPut(ExcelBook&,   "Saved", 1)
    ocxMethod(ExcelBook&,"Close")
    ocxMethod(Excel&, "Quit")
    ocxRelease(Range&, ExcelSheet&, ExcelBook&, WorkBooks&, Excel&)
    SENDMESSAGE(ExcelWnd&,16,0,0)'--WM_CLOSE an Excel
    ExcelWnd& = 0
    '*-------------------------------------------------------------------------------------------------*

ENDPROC

'*-------------------------------------------------------------------------------------------------*
[...]
'*-------------------------------------------------------------------------------------------------*
'Neue Zeile (=4 Excel-Zeilen) durch Kopieren der vorherigen (4 Excel-Zeilen) anlegen:
'*-------------------------------------------------------------------------------------------------*
Line% =  ExcelSheetLines& - 3
ocxMethod(ExcelSheet&,"Activate")
Range& = ocxGet(ExcelSheet&,"Range","A" + STR$(INT(Line%)) + ":AT" + STR$(INT(Line% + 3)))
ocxMethod(Range&, "Copy")
Line% = Line% + 4
Range& = ocxGet(ExcelSheet&,"Range","A" + STR$(INT(Line%)) + ":AT" + STR$(INT(Line% + 3)))
ocxMethod(Range&, "PasteSpecial")
[...]
'*-------------------------------------------------------------------------------------------------*
'Excelzelle einfügen:
'*-------------------------------------------------------------------------------------------------*
Zelle$  = "A1"
Inhalt$ ="Test"

IF Zelle$ <> ""

    Range& = ocxGet(ExcelSheet&, "Range", Zelle$)
    ocxPut(Range&, "Value", Inhalt$)'Anstelle von "Value" ggf auch "Text" probieren

ENDIF

[...]
'*-------------------------------------------------------------------------------------------------*
'Exceltabelle speichern und schließen:
'*-------------------------------------------------------------------------------------------------*
ocxMethod(ExcelSheet&, "Protect")
ocxMethod(ExcelBook& , "Save")
CloseExcelFile
=s1>'*-------------------------------------------------------------------------------------------------*

[OFFTOPIC]Stefan, I have your Posting edited, because I your slight "verunglückten" code-Tacks aale brought have.
Dietmar[/OFFTOPIC]
 
Schöne Grüße aus Wittgenstein
von Stephan

Programmierumgebung:| XProfan X4 | WIN10 | AMD FX6100 3,3 GHz
02/08/11  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

4.656 Views

Untitledvor 0 min.
Frank04/16/21
kustg05/14/19
Frank Vorholzer05/18/14
Michaeal10/18/12
More...

Themeninformationen

this Topic has 2 subscriber:

Stephan Sonneborn (1x)
iF (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie