[Dropped] Macro to rename sheet from cell value
[Dropped] Macro to rename sheet from cell value
I am trying to create a macro that will rename the current sheet (Say Sheet 5) to the value of a cell in the current sheet
eg: in Cell A1 I have "2017"
in Cell B1 I have "1" (To represent the month of January)
in cell C1 I have "1" (To represent the 1st day of the month)
in cell D1 I have a Variable such as a,b,c,d etc. (Say I have "a")
in Cell E1 I have all the values above combined to give me a cell value of "1Jan2017a"
I want to be able to run a macro that will rename the current sheet with the value of cell E1, So the result will be a sheet called "1Jan2017a"
I have tried all the macros in this forum for similar topics but they have not worked.
Your help would be appreciated.
Thank-you
eg: in Cell A1 I have "2017"
in Cell B1 I have "1" (To represent the month of January)
in cell C1 I have "1" (To represent the 1st day of the month)
in cell D1 I have a Variable such as a,b,c,d etc. (Say I have "a")
in Cell E1 I have all the values above combined to give me a cell value of "1Jan2017a"
I want to be able to run a macro that will rename the current sheet with the value of cell E1, So the result will be a sheet called "1Jan2017a"
I have tried all the macros in this forum for similar topics but they have not worked.
Your help would be appreciated.
Thank-you
Last edited by MrProgrammer on Tue Dec 05, 2023 4:44 pm, edited 1 time in total.
Reason: Dropped: No attachment provided when requested -- MrProgrammer, forum moderator
Reason: Dropped: No attachment provided when requested -- MrProgrammer, forum moderator
ESmith
Open Office 4.1.0
Windows Vista
Open Office 4.1.0
Windows Vista
Re: Using a Macro to rename a sheet to a cell value
Disclaimer; I don't use macros.
It seems that the solution in viewtopic.php?f=9&t=5693 is almost what you want. Just take out the loop and modify the cell addresses as needed.
It seems that the solution in viewtopic.php?f=9&t=5693 is almost what you want. Just take out the loop and modify the cell addresses as needed.
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 25.2.4.3; SlackBuild for 25.2.4 by Eric Hameleers
---------------------
Apache OpenOffice 4.1.15
LibreOffice 25.2.4.3; SlackBuild for 25.2.4 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue]
Unexpected '{' on line 32
.Re: Using a Macro to rename a sheet to a cell value
I tried the editing the script mentioned in the link above but didn't work:
Sub Main
Dim oSheet
Dim oCell
oSheet = ThisComponent.Sheets
oCell = oSheet.getCellRangeByName("A1")
oSheet.Name = oCell.String
End Sub
Any other suggestions?
Sub Main
Dim oSheet
Dim oCell
oSheet = ThisComponent.Sheets
oCell = oSheet.getCellRangeByName("A1")
oSheet.Name = oCell.String
End Sub
Any other suggestions?
ESmith
Open Office 4.1.0
Windows Vista
Open Office 4.1.0
Windows Vista
Re: Using a Macro to rename a sheet to a cell value
Code: Select all
oSheet = ThisComponent.Sheets
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Using a Macro to rename a sheet to a cell value
Instead of macro programming, you'd better learn how to organize data efficiently so you can use this software (or any other software for that matter) without extra coding.
Getting information from separate lists is very difficult. Keeping multiple lists for the same class of information is one of the most toxic beginner's mistakes.
Look at one of my example spreadsheets:
download/file.php?id=23902
The first sheet named "Data" has 1000 records in random order below a single row of column headers. This is called a "normalized list". Software can deal very well with normalized lists. You can insert a new row anywhere in that list in oder to add a new record. The position does not matter. Insert rows and keep the order of columns. Put dates below dates, values below values, names below names. Just avoid row #2 for insertion. Due to a design flaw, OpenOffice would copy the format attributes from the header row.
The header row includes auto-filter buttons. They help you to filter this list in place in order to see only the records you are interested in. This is way more convenient than finding the right sheet where to add/remove/edit the information. There are other filtering tools where you can specify multiple filter criteria. Sometimes you may want a certain category copied to a separate sheet. Even that is possible.
You can also click any single cell in that list and click one of the sort buttons [A-Z] or [Z-A] in order to sort the whole list by the clicked column.
More importantly a single normalized list allows you to aggregate your data by means of software tools. With a few clicks you can get the sum, count, average, min, max, median for any combination of years, quarters, months, days, weeks, category names or person names as demonstrated by the "Pilot" sheets. "Data Pilots", also known as "Pivot Tables" are described here: https://wiki.openoffice.org/wiki/Docume ... /DataPilot
Filtering, sorting, pivot tables, menu:Data>Subtotals ..., database functions and various other spreadsheet functions (SUMIF, SUBTOTAL, SUMPRODUCT) let you derive information from a normalized list.
Getting information from separate lists is very difficult. Keeping multiple lists for the same class of information is one of the most toxic beginner's mistakes.
Look at one of my example spreadsheets:
download/file.php?id=23902
The first sheet named "Data" has 1000 records in random order below a single row of column headers. This is called a "normalized list". Software can deal very well with normalized lists. You can insert a new row anywhere in that list in oder to add a new record. The position does not matter. Insert rows and keep the order of columns. Put dates below dates, values below values, names below names. Just avoid row #2 for insertion. Due to a design flaw, OpenOffice would copy the format attributes from the header row.
The header row includes auto-filter buttons. They help you to filter this list in place in order to see only the records you are interested in. This is way more convenient than finding the right sheet where to add/remove/edit the information. There are other filtering tools where you can specify multiple filter criteria. Sometimes you may want a certain category copied to a separate sheet. Even that is possible.
You can also click any single cell in that list and click one of the sort buttons [A-Z] or [Z-A] in order to sort the whole list by the clicked column.
More importantly a single normalized list allows you to aggregate your data by means of software tools. With a few clicks you can get the sum, count, average, min, max, median for any combination of years, quarters, months, days, weeks, category names or person names as demonstrated by the "Pilot" sheets. "Data Pilots", also known as "Pivot Tables" are described here: https://wiki.openoffice.org/wiki/Docume ... /DataPilot
Filtering, sorting, pivot tables, menu:Data>Subtotals ..., database functions and various other spreadsheet functions (SUMIF, SUBTOTAL, SUMPRODUCT) let you derive information from a normalized list.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Using a Macro to rename a sheet to a cell value
Hallo
+1 for Villeroy…
but anyway- assuming cell E1 is already selected:
+1 for Villeroy…
but anyway- assuming cell E1 is already selected:
Code: Select all
sub rename_current_sheet()
doc = ThisComponent
cell = doc.CurrentSelection
sheet = cell.Spreadsheet
sheet.Name = cell.String
End Sub
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Re: Using a Macro to rename a sheet to a cell value
but then again - assuming cell E1 is NOT selected:but anyway- assuming cell E1 is already selected:
Code: Select all
sub rename_current_sheet()
Dim oDoc, oSheet, oCell
oDoc = ThisComponent
oSheet = oDoc.getCurrentController.getActiveSheet
oCell = oSheet.getCellByPosition(4,0) 'cell E1
oSheet.Name = oCell.String
End Sub
____________
DiGro
AOO 4.1.15 (Dutch) on Windows 11. Scanned with Ziggo Safe Online (F-Secure)
DiGro
AOO 4.1.15 (Dutch) on Windows 11. Scanned with Ziggo Safe Online (F-Secure)
Re: Using a Macro to rename a sheet to a cell value
Can you really not see the value to change? In the array that is the cells, all values start with 0, so 4,0 is E,1; A=0, B=1, C=2, D=3,E=4 and Row 1 in the spreadsheet maps to row 0 in the internal array.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
Re: Using a Macro to rename a sheet to a cell value
Thanks for Trying But Neither of the two examples above work. I get a Basic Syntax error on line "doc = ThisComponent"
ESmith
Open Office 4.1.0
Windows Vista
Open Office 4.1.0
Windows Vista
Re: Using a Macro to rename a sheet to a cell value
Please upload your example .ods file with the embedded macro code here.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Using a Macro to rename a sheet to a cell value
Works for me though
____________
DiGro
AOO 4.1.15 (Dutch) on Windows 11. Scanned with Ziggo Safe Online (F-Secure)
DiGro
AOO 4.1.15 (Dutch) on Windows 11. Scanned with Ziggo Safe Online (F-Secure)
Re: Using a Macro to rename a sheet to a cell value
In order to make the green button functional:DiGro wrote:Works for me though
View>Toolbars>Form Design
Toggle OFF the 2nd button from the left ("Toggle Design Mode")
Toggle OFF the 4th button from the right ("Open in Design Mode")
Save
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice