Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 2 Jahren, 5 Monaten
Letzter Beitrag:
vor 2 Jahren, 4 Monaten
Beteiligte Autoren:
Stefan Bentvelsen, Gianni Spano, Peter Holemans

[WD19] Print settings Excel via xlsDocument variable

Startbeitrag von Stefan Bentvelsen am 04.09.2015 09:06

Hi all,

I create in my software an Excel-file via xlsDocument, xlsColumn and xlsCell variables.
That works quit good. But is it also possible to set a number of print settings via this xlsDocument variable ?

I would like to set the print orientation to Landscape, the marges to Small and the scale to Fitting for one page.


Anyone ?

von Stefan Bentvelsen - am 08.09.2015 06:52
Hi Stefan,

This won't work with the standard xlsxxx functions as these create a standard application independent workbook file.
You'll need to do this using ole with Excel.

XLSApp is object dynamic
XLSApp = Excel.application

and so on and so on...

We have several Excel generators that even create Excel workbooks with pivot-tables in them.
Works great as long as the data sets to transfer via ole are not too big (

von Peter Holemans - am 08.09.2015 07:54
Hi Peter,

it took some time, but I've managed to make these settings in my genereted Excel-document. I've a little problem left. If I save the document via:


then a dialog is started by Excel that stated that the document already exist, if I want to overwrite it. Of course I want to overwrite it, but would like to save the document without dialog.

Do you know a way to save the document without dialog ?

Thanks in advance.

von Stefan Bentvelsen - am 18.09.2015 10:57
Hello Stefan

Try to put this line of code before of ":m_pautExcel>>ActiveWorkbook.......:"


and restore the alerts after the write of file.
So the complete code should be as:


Hope in this help


von Gianni Spano - am 18.09.2015 11:19

Re: [WD19] Print settings Excel (SOLVED !)

Hi Gianni,

thank you very much ! It works perfect.

This is my code now:

:m_pautExcel>>DisplayAlerts = False
:m_pautExcel>>DisplayAlerts = True

von Stefan Bentvelsen - am 18.09.2015 11:57

Re: [WD19] Print settings Excel

A little problem now is that the opening of the Excel-document after saving it, does not work anymore.

I use ShellExecute(lsName) for that and it worked before disabling the dialog and now it's not. It starts Excel, but directly closes it after that. From Windows Explorer I can doubleclick on the Excel document and it opens as expected. Why not via ShellExecute anymore ?

von Stefan Bentvelsen - am 18.09.2015 14:33

Re: [WD19] Print settings Excel (SOLVED TOO)

The problem was that Excel does quit in my program. But because the class (CExcel) I use for setting the print settings was not declared in a separate procedure, Excel.exe still was in memory in the background. On the toolbar it was gone. So putting the piece of code in a separate procedure solved the problem. The class is now deleted from memory when the procedure end is reached and ShellExecute works OK now.

May be it help someone in future.

von Stefan Bentvelsen - am 28.09.2015 19:18
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.