In VBA "Sheet Code Name " is there and It has many Advantages...Does LibreOffice Calc - have Same Feature have in Macro?

Hello Friends,
In VBA macro, we can edit the Sheet Code Name and It has many advantages…
like We Don’t Use
Workbooks(“Book1.xlsx”) or Workbooks(“Collection_Example.xlsx”)
or
Workbooks(1) or ActiveWorkbook or ThisWorkbook
or
Worksheets(“Sheet1”) or Worksheets(1) or Sheets(“Sheet1”) or Sheets(1)

We can directly use the “Sheet Code Name” Like this

' Get The Range For Reading Data
    Dim rng As Range
    Set rng = shData.Range("A1").CurrentRegion

and …

' Writing Data in E1
    Dim item As Variant, row As Long
    row = 1
    For Each item In myColl
        shData.Cells(row, 5).Value = item
        row = row + 1
    Next item

Here, shData is "Sheet Code Name"
shData.Range(“A1”).CurrentRegion
and
shData.Cells(row, 5).Value = item

Like this Feature in VBA … Does LibreOffice Calc have Same Feature have ? in Macro.
Because, Writing Long Code Very Messy …Please Help …

Here is the Screen Shots For Easy Under Standings…
.

I have Writing Both VBA and BASIC Code here and get the results

  1. VBA
    ======
    a) WorkSheets or Sheets Name or Index
    =============================

b) Sheet Code Name

c) VBA Code and get Results in E1

Sub Read_Write_IntheWorkSheets_WithHeader()
    Dim myColl As Collection
    Set myColl = New Collection
    
    ' Get The Range For Reading Data
    Dim rng As Range
    Set rng = shData.Range("A1").CurrentRegion
      
    ' Reading Data Including Header
    Dim i As Long
    For i = 1 To rng.Rows.Count
        If rng.Cells(i, 2).Value > 70 Or i = 1 Then
            myColl.Add rng.Cells(i, 1).Value
        End If
    Next i
    
    ' Writing Data in E1
    Dim item As Variant, row As Long
    row = 1
    For Each item In myColl
        shData.Cells(row, 5).Value = item
        row = row + 1
    Next item
End Sub
  1. BASIC
    =======
    a) LibreOffice_Calc_ SheetName or Sheet Index
    ======================================

image

b) LibreOffice _ Calc _ BASIC Code and get Results

Sub Reading_Data_From_Sheets
		Dim myColl As  New Collection
		Set myColl = New Collection
		
		' Identifying The Data Range For Reading
		Doc = ThisComponent : Sheet = Doc.Sheets.getByName("Marks_Class_B")
		Cell = Sheet.getCellRangeByName("A1")
		
		Cursor = Sheet.createCursorByRange(Cell)
		Cursor.collapseToCurrentRegion
		
		' Select GuI
		view = Doc.CurrentController : frame = view.getFrame()
		frame.Activate : view.Select(Cursor)
		
		' Reading Data Starts From Header Row
		Dim i As Long 
		For i = 0 To Cursor.Rows.Count
				If Cursor.Spreadsheet.getCellByPosition(1, i).Value > 70 or i = 0Then
						myColl.Add Cursor.Spreadsheet.getCellByposition(0, i).String
				End if
		Next i
		
        ' Write The Data in to the Range("E1")
		Dim item As Variant, row As Long
		row = 0
			For Each item In myColl
					Sheet.getCellByPosition(4, row).String = item
					row = row + 1		
			Next item	
End Sub

Please Help…the "Sheet Code Name"

Is that a question?
.
Maybe you search the WITH-Statement:
https://help.libreoffice.org/latest/ro/text/sbasic/shared/03090411.html

Ok it seems you think short is better, as you don’t even write a complete sentence. But actually in my opinion to ask first for the active sheet or refer to a name or index gives cleaner code than to refer an “we all know there is shdata to access something”. But I apologise for this long and “messy” statement, use imho short more messy

1 Like

Hi Wanderer Thanks for replying , Yes, I know the With statement… also With … End With Statement also there in VBA … But, I want " Code Name " Or "Sheet Code Name " LIke VBA have…
Is there Any kind Of Feature in available in LibreOffice Calc _ Macro …
I saw … the MRI … Code Name there… You have any Idea…

As far as I know only the language is nearly identical, if you use BASIC. The DOM or API is completely different.
.
You may use the switch for VBA compatibility, but I don’t know in detail, what it changes…

1 Like

Yes, I also agree … API is different in VBA vs BASIC… but… I want only ( Sheet " Code Name" )…In Libreoffice Calc Macro… rather than Sheets(“Sheet Name”) or Sheet(1)…

Yes, it is there - as a sheet property:

No, you cannot use this text string as a sheet object

1 Like

CodeName - String in MRi …
How to use in Macro…sample Code please…
What is the Difference between " Code Name " v/s " Name " in the MRI Screen shots Metioned…Because both have String data type

Once more:

You can write a function that iterates through all the sheets in the workbook and returns a sheet object whose codename is the same as the text string you specify. But you won’t be able to use the string you provide in your question, shData.Range(“A1”). Forget it! There is simply no such possibility.

Yes it is. But the Sheets object has a getByName() method, which works specifically with the Name, but not with the CodeName

2 Likes

Thanks JohnSUN with clear Explanation…