Bug 167178 - Calc. Macro assigns sheets by index, not by variable
Summary: Calc. Macro assigns sheets by index, not by variable
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
25.2.4.3 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:26.2.0 target:25.2.5 target:25...
Keywords: bisected, regression
: 167175 167249 (view as bug list)
Depends on:
Blocks:
 
Reported: 2025-06-23 20:01 UTC by lumentulo
Modified: 2025-07-01 07:09 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lumentulo 2025-06-23 20:01:31 UTC
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.
Comment 1 Mike Kaganski 2025-06-24 07:07:13 UTC
*** Bug 167175 has been marked as a duplicate of this bug. ***
Comment 2 Mike Kaganski 2025-06-24 07:11:47 UTC Comment hidden (obsolete)
Comment 3 Mike Kaganski 2025-06-24 07:22:30 UTC Comment hidden (obsolete)
Comment 4 Mike Kaganski 2025-06-24 15:16:38 UTC
https://gerrit.libreoffice.org/c/core/+/186906
Comment 5 Mike Kaganski 2025-06-24 15:19:22 UTC
Actually, that was after a0403b6eb25a99f6225e0f77f4b14d78f4045c9e.
Comment 6 Commit Notification 2025-06-24 17:17:00 UTC
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.
Comment 7 Zdenek Borecky 2025-06-25 08:41:22 UTC
Thanks very much!
Comment 8 lumentulo 2025-06-25 18:53:15 UTC
Still not fixed in 25.2.5.0.0 build from June 25, 2025 04:35
Comment 9 Mike Kaganski 2025-06-26 04:01:21 UTC
(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.
Comment 10 Mike Kaganski 2025-06-26 16:38:17 UTC
*** Bug 167249 has been marked as a duplicate of this bug. ***
Comment 11 Commit Notification 2025-06-27 11:05:59 UTC
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.
Comment 12 Commit Notification 2025-07-01 07:09:34 UTC
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.