Description: Good day to you. Problem is that assigning a sheet to a variable, varible then refers to a sheet that had the initial index. Example: Let's assume there are two sheets in a workbook - SheetOne and SheetTwo. I create variables - sheet_one and sheet_two - and assign them respectively. Then I insert a sheet at a position number 0 — after that var sheet_one refers to a newly created sheet and var sheet_two refers to SheetOne. Works for both Option VBASupport 0 and 1. ```basic Option VBASupport 1 Public Sub Main() With ThisWorkbook.Worksheets Dim sheet_two As Worksheet Set sheet_two = .Item("SheetTwo") .Add Before:=.Worksheets(1) End With Debug.Print sheet_two.Name ' --> "SheetOne" instead of "SheetTwo" End Sub ``` ``` Option VBASupport 0 Public Sub Main() With ThisComponent.Sheets Dim sheet_two As Object sheet_two = .GetByName("SheetTwo") .InsertNewByName("NewShiny", 0) End With Print sheet_two.Name ' --> "SheetOne" instead of "SheetTwo" End Sub ``` Actual Results: "SheetOne" Expected Results: "SheetTwo" Reproducible: Always User Profile Reset: No Additional Info: Macro should correctly assign objects to variables.
*** Bug 167175 has been marked as a duplicate of this bug. ***
Looks like a regression. I suspect my 78a66f99958ed258686cb2fac90f361954b5afe4.
Yes, exactly that 78a66f99958ed258686cb2fac90f361954b5afe4.
https://gerrit.libreoffice.org/c/core/+/186906
Actually, that was after a0403b6eb25a99f6225e0f77f4b14d78f4045c9e.
Mike Kaganski committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/1761796355277ba3a47143729e027a829802b4a3 tdf#167178: make sure to synchronize the tab in AdjustUpdatedRanges It will be available in 26.2.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.
Thanks very much!
Still not fixed in 25.2.5.0.0 build from June 25, 2025 04:35
(In reply to lumentulo from comment #8) > Still not fixed in 25.2.5.0.0 build from June 25, 2025 04:35 Which is obvious, given the text in comment 6.
*** Bug 167249 has been marked as a duplicate of this bug. ***
Mike Kaganski committed a patch related to this issue. It has been pushed to "libreoffice-25-2": https://git.libreoffice.org/core/commit/5d3a4e6857678f5207aff8669e43c74b91cf3f87 tdf#167178: make sure to synchronize the tab in AdjustUpdatedRanges It will be available in 25.2.5. 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.
Mike Kaganski committed a patch related to this issue. It has been pushed to "libreoffice-25-8": https://git.libreoffice.org/core/commit/b8df40c4fbef42c2c51258aaed03591b1ff0934c tdf#167178: make sure to synchronize the tab in AdjustUpdatedRanges It will be available in 25.8.0.0.beta2. 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.
Created attachment 201601 [details] File with a macro to explain a problem
Good day to you. As of LibreOfficeDev_25.2.6.0.0_Win_x86-64.msi build from 2025-07-02_06.37.52 It seems, part with no Option VBASupport works great. Although part with Option VBASupport 1 gets me an error "Object variable not set" when I try to fetch sheet's name. ``` Option VBASupport 1 Public Sub Main() With ThisWorkbook Dim sheet_two As Worksheet Set sheet_two = .Worksheets("SheetTwo") Worksheets.Add Before:=.Worksheets(1) End With Debug.Print sheet_two.Name ' --> "SheetOne" instead of "SheetTwo" End Sub ```
(In reply to lumentulo from comment #14) Did you try Print instead of Debug.Print? Which is completely unrelated to this issue.
Works with just "Print" perfectly. Thank you. I forgot there is no "Debug" in any way in LibreOffice Basic.
I tested versions 25.2.6 dev 2025-07-02_06.24.58 and 2025-07-08_06.01.51 It works perfectly. Thank you. But next in my code I use strComp() for sort of new inserted sheet and function ThisComponent.Sheets.moveByName(name, index) move sheet after the index. It moved before the index in 25.2.3.2 and older versions. It is no problem for me, I will change my code.
(In reply to Zdenek Borecky from comment #17) > But next in my code I use strComp() for sort of new inserted sheet > and function ThisComponent.Sheets.moveByName(name, index) move sheet after > the index. > It moved before the index in 25.2.3.2 and older versions. This is completely different. It would be nice if you created a separate bug report for this, with a reproducer, that we could investigate.