Bug 149786 - VBA ExportAsFixedFormat to Export As PDF
Summary: VBA ExportAsFixedFormat to Export As PDF
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Balázs Varga (allotropia)
URL: https://learn.microsoft.com/en-us/off...
Whiteboard: target:7.6.0
Keywords:
: 139508 (view as bug list)
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2022-06-30 09:04 UTC by Óvári
Modified: 2024-03-21 22:55 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
ExportAsPDF.xls (63.00 KB, application/vnd.ms-excel)
2022-06-30 09:04 UTC, Óvári
Details
ExportAsPDF.pdf (388.38 KB, application/pdf)
2022-06-30 09:06 UTC, Óvári
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Óvári 2022-06-30 09:04:36 UTC
Created attachment 181030 [details]
ExportAsPDF.xls

Please enable VBA compatibility support for Microsoft Excel 2010 VBA code to export as PDF.

Attached is the MS Excel spreadsheet with the macro:

```
Sub ExportAsPDF()
    ActiveSheet.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=".\ExportAsPDF.pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
End Sub
```

When the macro code is run with LibreOffice Community 7.3.4.2 an error occurs:
BASIC runtime error
'423'
Property or method not found: ExportAsFixedFormat.

The output `ExportAsPDF.pdf` will be attached in a later as only 1 attachment is allowed.

Thank you
Comment 1 Óvári 2022-06-30 09:06:00 UTC
Created attachment 181031 [details]
ExportAsPDF.pdf

Output PDF file from MS Excel 2010 when running the macro `ExportAsPDF()`.
Comment 3 Óvári 2022-07-03 21:18:26 UTC
(In reply to m.a.riosv from comment #2)
Thank you for your response.


At “Projects selected for LibreOffice in the Google Summer of Code 2022”
https://blog.documentfoundation.org/blog/2022/05/26/projects-selected-for-libreoffice-in-the-google-summer-of-code-2022/
Ilmari Lauhakangas wrote:
I think the best way is to create a new bug report for each missing function and add 108908 to the “Blocks” field.
To see what is already covered in the bug tracker, see the dependency tree of the meta bug: https://bugs.documentfoundation.org/showdependencytree.cgi?id=108908&hide_resolved=1
Isn’t “ExportAsFixedFormat” a missing function in LO VBA compatibility?


Saving (or exporting) as PDF does not require a virtual PDF printer driver to be installed.

LibreOffice Calc → Menu Bar → File → Export as PDF… enables PDFs to be created without using a virtual PDF printer.

LibreOffice VBA compatibility support printing to a printer; however, VBA compatibility does not currently support PDF exporting. Surely this is a feature that is required as more processes become digitised?


It seems that the VBA syntax of the “ExportAsFixedFormat” method is generally as follows:
expression.ExportAsFixedFormat (Type, Filename, Quality, IncludeDocProperties, IgnorePrintAreas, From, To, OpenAfterPublish)

Internet search of “vba export as pdf” finds pages like:

Excel VBA Save As PDF: Step-By-Step Guide And 10 Code Examples To Export Excel To PDF
https://powerspreadsheets.com/save-excel-file-pdf-vba/

Excel VBA to Export Selected Sheets to PDF
https://stackoverflow.com/questions/20750854/excel-vba-to-export-selected-sheets-to-pdf

Save Excel as PDF with VBA
https://exceloffthegrid.com/vba-code-save-excel-file-as-pdf/

Can the status of this issue please be set to NEW?


Thank you
Comment 4 Gabor Kelemen (allotropia) 2023-01-10 09:26:43 UTC
Still happens in

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 44355a90b3450111ad87ad4b6607a564e41d7b54
CPU threads: 14; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: de-DE (hu_HU); UI: en-US
Calc: threaded

This method is not implemented, but should/could be.
Comment 5 Gabor Kelemen (allotropia) 2023-02-07 13:04:56 UTC
*** Bug 139508 has been marked as a duplicate of this bug. ***
Comment 6 Commit Notification 2023-02-14 10:41:29 UTC
Balazs Varga committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/85d1ead3f9f23f78db0eee161eb0fc199d4b766c

tdf#149786 sc: add VBA function: ExportAsFixedFormat

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 7 Óvári 2023-02-14 20:01:46 UTC
Thanks for Balázs your commit.

Can you please advise which modules ExportAsFixedFormat works for in LibreOffice?

This information will enable updating "LibreOffice 7.6 Community: Release Notes" at https://wiki.documentfoundation.org/ReleaseNotes/7.6#VBA_Support
Comment 8 Óvári 2023-02-14 20:13:26 UTC
Does your fix work using either Windows or GNU/Linux without code modification?

Use case:
On Windows, backslash \ is used
On GNU/Linux, forward-slash / is used

For other Windows and GNU/Linux, does the line work without modification from the user:
Filename:=".\ExportAsPDF.pdf", _

Does the code automatically transcribe the line to:
Filename:="./ExportAsPDF.pdf", _

Thank you
Comment 9 Gabor Kelemen (allotropia) 2023-02-15 12:46:47 UTC
(In reply to Óvári from comment #8)
> Does your fix work using either Windows or GNU/Linux without code
> modification?
> 
> Use case:
> On Windows, backslash \ is used
> On GNU/Linux, forward-slash / is used
> 
> For other Windows and GNU/Linux, does the line work without modification
> from the user:
> Filename:=".\ExportAsPDF.pdf", _
> 
> Does the code automatically transcribe the line to:
> Filename:="./ExportAsPDF.pdf", _
> 
> Thank you

Hi

I have tested this with the example file attachment 185348 [details] for bug 153593.
The following example filename specifications all work under a fresh Linux build:
        Filename:=Application.ActiveWorkbook.Path & ".\ExportAsPDF_fp.pdf", _
        Filename:=".\ExportAsPDF_dot.pdf", _
        Filename:="ExportAsPDF_fn.pdf", _

I also tested with the following filename specification from duplicate bug 139508:
        Filename:=wb.Path & "\" & "export" & "\" & "pdf" & ".pdf", _
This does not work on Linux without manually changing the slashes.

Also the other methods in that macro with similarly hand-provided slashes don't work either:
If Dir(wb.Path & "\" & "export", vbDirectory) = "" Then
                        MkDir (wb.Path & "\" & "export")
                End If

Handling this would be another interesting development opportunity :).
Comment 10 Gabor Kelemen (allotropia) 2023-02-15 12:49:42 UTC
(In reply to Óvári from comment #7)
> Thanks for Balázs your commit.
> 
> Can you please advise which modules ExportAsFixedFormat works for in
> LibreOffice?
> 
This is currently Calc-only.

There are similar methods in Word and PowerPoint, this patch does not cover those uses:
https://learn.microsoft.com/en-us/office/vba/api/word.document.exportasfixedformat 
https://learn.microsoft.com/en-us/office/vba/api/powerpoint.presentation.exportasfixedformat 

> This information will enable updating "LibreOffice 7.6 Community: Release
> Notes" at https://wiki.documentfoundation.org/ReleaseNotes/7.6#VBA_Support

Nice, thanks!
Comment 11 Gabor Kelemen (allotropia) 2023-02-15 14:13:51 UTC
Filed a new bug 153635 about platform-independent path separators, otherwise I think this works quite okay now.
Comment 12 Commit Notification 2023-02-18 18:24:27 UTC
Balazs Varga committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/0a27403bbc36c89efa321fb3c5061fe4ee7095fb

Related tdf#149786: add better unit test for vba pdf export macro

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 zieme 2023-11-21 07:52:23 UTC Comment hidden (spam)
Comment 14 assessslacks 2023-12-14 06:54:16 UTC Comment hidden (spam)
Comment 15 bryanklandin 2024-03-21 22:55:48 UTC Comment hidden (spam)