Bug 139939 - vba compatible copying worksheets to a new workbook doesn't work for more than one sheets
Summary: vba compatible copying worksheets to a new workbook doesn't work for more tha...
Status: RESOLVED INSUFFICIENTDATA
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.4.6.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2021-01-27 04:10 UTC by Harald Langheinrich
Modified: 2023-09-13 03:17 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Example file based on comment 3 (14.54 KB, application/vnd.ms-excel.sheet.macroEnabled.12)
2023-02-13 19:17 UTC, Gabor Kelemen (allotropia)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Langheinrich 2021-01-27 04:10:20 UTC
Description:
Option VBASupport 1
Option Compatible
Option explicit
Sub test
	Dim BasisDateiName As string
	Dim DateiName As String
	Dim PfadName As String
	Dim PfadDateiName As String
	
	BasisDateiName="WM_ImmobilienService.ods"
	DateiName ="Test.xlsx"
	PfadName="/home/harald/Dokumente/WM_ImmobilienService/Auftrag/"
	'Neue AuftragsMappe erstellen 	
	PfadDateiName =	PfadName & DateiName
	
	'On Error Resume Next
		Workbooks(BasisDatei_Name).Worksheets(Array("Auftrag","Nachweis")).Copy		
		ActiveWorkbook.SaveAs filename:=PfadDateiName
	'on error goto 0
	
End Sub 

Workbooks(BasisDatei_Name).Worksheets(Array("Auftrag","Nachweis")).Copy
definitly works correctly but throws error  com.sun.star.container.NoSuchElementException

With On error resume next i can force it to do the expected work like MS-excel

Since last update it does only the first sheet




Steps to Reproduce:
run it

Actual Results:
not usable any more 

Expected Results:
should work as in MS excel without error message !!!


Reproducible: Always


User Profile Reset: Yes


OpenGL enabled: Yes

Additional Info:
[Information automatically included from LibreOffice]
Locale: de
Module: SpreadsheetDocument
[Information guessed from browser]
OS: Linux (All)
OS is 64bit: yes
Comment 1 himajin100000 2021-02-11 15:41:19 UTC
source code pointer:

https://opengrok.libreoffice.org/xref/core/sc/source/ui/vba/vbaworksheets.cxx?r=bb06f513#443
https://opengrok.libreoffice.org/xref/core/sc/source/ui/vba/vbaworkbook.cxx?r=0c1b4904#237
https://opengrok.libreoffice.org/xref/core/sc/source/ui/vba/vbaworksheet.cxx?r=85b40048#553

currently ScVbaWorksheets does not have Copy method etc., ScVbaWorksheet does.

Aside from this main point, we have to be careful of the following two points.
1. VbaWorksheets nor ScVbaWorksheet has SaveAs method.
2. THIS METHOD HAS A BUG: see Bug 118146

https://bugs.documentfoundation.org/show_bug.cgi?id=118146
Comment 2 himajin100000 2021-02-11 15:43:19 UTC
typo:

wrong : VbaWorksheets nor ScVbaWorksheet has SaveAs method.
correct :neither ScVbaWorksheets nor ScVbaWorksheet has SaveAs method. ScVbaWorkbook does.
Comment 3 Harald Langheinrich 2021-02-11 16:15:24 UTC
copy without a target has destination activeworkbook and activeworkbbok has as method .saveas

this is an example from microsoft

Worksheets(Array("Sheet1", "Sheet2", "Sheet4")).Copy
With ActiveWorkbook
     .SaveAs Filename:=Environ("TEMP") & "\New3.xlsx", FileFormat:=xlOpenXMLWorkbook 
     .Close SaveChanges:=False 
End With 


in open office with option VBASupport on this is also possible, but an error is generated and the last page in the array disappears from the new workbook. That's what i'm talking about.

if I use  on error resume next everything is working as expected!!
Comment 4 himajin100000 2021-02-11 16:18:59 UTC
> activeworkbook has as method .saveas

sorry, I missed this one.
Comment 5 Gabor Kelemen (allotropia) 2023-02-13 19:17:24 UTC
Created attachment 185359 [details]
Example file based on comment 3

I tried to reproduce this issue based on the example code in comment #3 but this seems to work in 6.4.0, 7.0.0, and current master.
All 3 sheets are present in the exported file.
Comment 6 Gabor Kelemen (allotropia) 2023-02-13 20:33:46 UTC
Could you please create an example file that shows the problem?
I tried to use the code in the Description, but can't get that one working.
Comment 7 QA Administrators 2023-08-13 03:20:18 UTC Comment hidden (obsolete)
Comment 8 QA Administrators 2023-09-13 03:17:29 UTC
Dear Harald Langheinrich,

Please read this message in its entirety before proceeding.

Your bug report is being closed as INSUFFICIENTDATA due to inactivity and
a lack of information which is needed in order to accurately
reproduce and confirm the problem. We encourage you to retest
your bug against the latest release. If the issue is still
present in the latest stable release, we need the following
information (please ignore any that you've already provided):

a) Provide details of your system including your operating
   system and the latest version of LibreOffice that you have
   confirmed the bug to be present

b) Provide easy to reproduce steps – the simpler the better

c) Provide any test case(s) which will help us confirm the problem

d) Provide screenshots of the problem if you think it might help

e) Read all comments and provide any requested information

Once all of this is done, please set the bug back to UNCONFIRMED
and we will attempt to reproduce the issue. Please do not:

a) respond via email 

b) update the version field in the bug or any of the other details
   on the top section of our bug tracker

Warm Regards,
QA Team

MassPing-NeedInfo-FollowUp