Announcement

Collapse
No announcement yet.

Excel: HPageBreaks.Add

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Excel: HPageBreaks.Add

    Hi everyone

    Coming form VB6, i'm converting some of my code to PB (PB/Win 9).
    So far i'm quite successful, but there's one tiny bit I need help with:

    I simply don't get how to insert a horizontal page break in an Excel worksheet.

    Here's the code stripped down to this function in the last version I tried.

    (excel_dispatch.inc is a newly exported .inc from Powerbasic COM Browser with options set to "Generate Dispatch Interface Only" and Interface Prefix "Int_xls_")

    Code:
    COMPILE EXE
    #DIM ALL
    #INCLUDE "excel_dispatch.inc"
    ''Objekt-Variablen
    GLOBAL oExcelApp       AS Int_xls__Application
    GLOBAL oExcelWorkbook  AS Int_xls__Workbook
    GLOBAL oExcelWorkSheet AS Int_xls__WorkSheet
    'OLE-Variablen
    GLOBAL vRead           AS VARIANT
    GLOBAL vWrite          AS VARIANT
    GLOBAL vTrue           AS VARIANT
    GLOBAL vRange          AS VARIANT
     
    FUNCTION PBMAIN () AS LONG
    vTrue = -1
    '' Excel öffnen
        oExcelApp = ANYCOM $PROGID_Excel_Application
        IF ISFALSE ISOBJECT(oExcelApp) OR ERR THEN
            MSGBOX "!!?!",, "ErrorMsg"
            EXIT FUNCTION
        END IF
    ''  Worksheet referenzieren
        OBJECT CALL oExcelApp.WorkBooks.Add TO oExcelWorkbook
        vWrite = 1
        OBJECT GET oExcelWorkBook.WorkSheets(vWrite) TO oExcelWorkSheet
        vRange = "a1"
        vWrite = "This is a test!"
        OBJECT LET oExcelWorksheet.Range(vRange).value = vWrite
        vRange = "a6"
        vWrite = "This as well!"
        OBJECT LET oExcelWorksheet.Range(vRange).value = vWrite
        ''Seitenumbruch?
    '--------------------------
    '''That's the part in question
        vWrite = "rows(5)"
        OBJECT CALL oExcelWorksheet.HPageBreaks.Add (vWrite)
    '--------------------------
        OBJECT LET oExcelApp.Visible = vTrue
        vWrite = 2 ''xlPageBreakPreview
        OBJECT LET oExcelApp.ActiveWindow.View = vWrite
     
    END FUNCTION
    Thanks for your help

    Greetings from Switzerland
    Markus
    Last edited by Markus Saegesser; 10 Oct 2008, 11:34 AM.

  • #2
    Got it!

    Now I'm a bit proud of myself - i finally got it.

    I needed one more Variant (let's call it "vRows"), and had to add
    one line while modifying another one.

    Here's the part I changed
    Code:
    vWrite = "5"
    OBJECT GET  oExcelWorksheet.Rows(vWrite) TO vRows  
    OBJECT CALL oExcelWorksheet.HPageBreaks.Add (vRows)
    Regards from Switzerland,
    Markus

    Comment

    Working...
    X