Bug 153635 - VBA Methods could handle file path separators OS-independently
Summary: VBA Methods could handle file path separators OS-independently
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
(earliest affected)
Inherited From OOo
Hardware: All Linux (All)
: medium enhancement
Assignee: Not Assigned
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
Reported: 2023-02-15 13:24 UTC by Gabor Kelemen (allotropia)
Modified: 2023-07-06 13:53 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:

Modified example file to run on Linux (9.23 KB, application/vnd.ms-excel.sheet.macroEnabled.12)
2023-02-15 13:24 UTC, Gabor Kelemen (allotropia)
The PDF created from attachment 181030 also has incorrect name (19.55 KB, image/png)
2023-02-15 13:44 UTC, Gabor Kelemen (allotropia)

Note You need to log in before you can comment on or make changes to this bug.
Description Gabor Kelemen (allotropia) 2023-02-15 13:24:30 UTC
Created attachment 185379 [details]
Modified example file to run on Linux

This is a continuation for bug 139508 and bug 149786

attachment 170014 [details] has the following macro:

Option VBASupport 1
Public Sub printplt1_click()
Dim pdf_template As Worksheet

 Set pdf_template = ActiveSheet
Dim wb As Workbook
Set wb = ActiveWorkbook
    Dim ws As Worksheet
If Dir(wb.Path & "\" & "export", vbDirectory) = "" Then
                        MkDir (wb.Path & "\" & "export")
                End If
  pdf_template.ExportAsFixedFormat Type:=xlTypePDF, _
                            Filename:=wb.Path & "\" & "export" & "\" & "pdf" & ".pdf", _
                            Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                            IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub

Now that ExportAsFixedFormat was implemented, this works on Windows.

However under Linux, all of Dir, MkDir and ExportAsFixedFormat fail because the paths / filenames are constructed using "\" as path separators, which is Windows-specific.

It would be nice if such path-handling methods would detect the user intention and interpret (or convert on file open?) these as the correct platform-specific path separators, i.e forward slashes.
Of course if such a path starts with "D:\" then all hope is lost, but macros with relative paths only could work platform-independently.

1. Open attachment 170014 [details]
2. Try to run the macro by clicking the button
-> This is supposed to create an export directory and a pdf.pdf from the document. 
This won't happen until you manually change all instances of the "\" to "/" in the macro editor.
I'm attaching a modified version of the attachment 170014 [details]. Now this does not run in Calc on Windows.

Version: (X86_64) / LibreOffice Community
Build ID: e2d8474857e8b39efcdf21441c95ad51a8aef6e8
CPU threads: 16; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: hu-HU (hu_HU.UTF-8); UI: hu-HU
Calc: threaded
Comment 1 Gabor Kelemen (allotropia) 2023-02-15 13:44:50 UTC
Created attachment 185381 [details]
The PDF created from attachment 181030 [details] also has incorrect name

Another example is attachment 181030 [details] from 149786: the 
        Filename:=".\ExportAsPDF.pdf", _
generates under Linux a filename literally starting with .\ (changing it to ./ fixes the behavior) while under Windows the correct ExportAsPDF.pdf is the result.
Comment 2 Óvári 2023-02-20 07:45:58 UTC
What issues are covered in this issue, i.e.
1. converting `/` to `\` if run on Windows
2. converting `\` to `/` if run on GNU/Linux

Hope this issue means both options.

Thank you