[Dropped] Macro help on setvalue
[Dropped] Macro help on setvalue
Hi all,
I'm trying to add the amount in Categories.B24 to the amount in Budget.B3 using setvalue() that gets run inside a macro. Presently I"m getting an error stating 'Object variable not set'
setValue(Categories.B24+Budget.B3)
I'm trying to add the amount in Categories.B24 to the amount in Budget.B3 using setvalue() that gets run inside a macro. Presently I"m getting an error stating 'Object variable not set'
setValue(Categories.B24+Budget.B3)
Last edited by MrProgrammer on Thu Feb 16, 2023 8:29 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
Open Office 4.1.1 on Windows 7
Re: Macro help on setvalue
Please upload all lines of your macro code. This one line is not enough for this task. You need get the Document, the Sheet, the source and target Cell/s/ first by API functions. Then you will able to set a value of a cell.setValue(Categories.B24+Budget.B3)
Do you want to create a custom Cellfunction or a Subroutine?
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: Macro help on setvalue
REM ***** BASIC *****
Sub Main
setValue(Categories.B24+Budget.B3)
End Sub
Sub Main
setValue(Categories.B24+Budget.B3)
End Sub
Open Office 4.1.1 on Windows 7
Re: Macro help on setvalue
Macros don't work like that. From what you have posted, setValue() doesn't exist as a function, you have to define it, and Categories.B24 & Budget.B3 don't have any meaning within the code. I know those sheets and cells exist in your spreadsheet, but the code doesn't know that. What do you want to do with the sum of the two cells?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Macro help on setvalue
Here is an example.
Sub Main
oDoc=ThisComponent
oSheet=oDoc.Sheets(0) 'Sheet1
oCell=oSheet.getcellrangebyname("C1")
A=oSheet.getcellrangebyname("A1")
B=oSheet.getcellrangebyname("B1")
oCell.setValue(A.value+B.value)
End Sub
Sub Main
oDoc=ThisComponent
oSheet=oDoc.Sheets(0) 'Sheet1
oCell=oSheet.getcellrangebyname("C1")
A=oSheet.getcellrangebyname("A1")
B=oSheet.getcellrangebyname("B1")
oCell.setValue(A.value+B.value)
End Sub
Re: Macro help on setvalue
Or you can get the Sheets by name:setValue(Categories.B24+Budget.B3)
...Code: Select all
oSheet=oDoc.Sheets(0) 'Sheet1
Code: Select all
Sub Main
Dim oDoc as object
Dim oSheets as object
Dim oSheet_Cat as object
Dim oSheet_Bud as object
Dim oCell_A as object
Dim oCell_B as object
Dim Value_A as double
Dim Value_B as double
oDoc = ThisComponent
oSheets = oDoc.Sheets
oSheet_Cat = oSheets.getByName("Categories")
oSheet_Bud = oSheets.getByName("Budget")
oCell_A = oSheet_Cat.getcellrangebyname("B24")
oCell_B = oSheet_Bud.getcellrangebyname("B3")
Value_A = oCell_A.value
Value_B = oCell_B.value
'...
' you can summarize the value_A and value_B, but I not understood it:
'-------------- Where you want to put the result??? --------------
oCell_somewhere.value = Value_A + Value_B
...
End sub
Last edited by Zizi64 on Sun Feb 12, 2017 5:43 pm, edited 1 time in total.
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: Macro help on setvalue
In other words: You have to write program. A program is not a magic spell.
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: Macro help on setvalue
Thanks so much for trying to help me out!
I suspected that I didn't have a good understanding of the macro scripting.
Here's what I'm trying to do. I have a budget.
I have three sub-sheets within my spreadsheet.
1-Budget - How much each week needs to go into each Category
Category Weekly Amount
Mortgage $90
Internet $7.25
Cell Phone $20
etc..
2-More Info - account numbers, addresses, notes about bills, etc.
3-Categories - What is the current total in each Category
Categories Amount
Mortgage $180
Internet $14.50
Cell Phone $40
etc.
So I am trying to create a Button in the Category SubSheet that would do the following:
1-Are you sure you want to add a week's paycheck to each category?
Allow Yes or No response to user
2-If YES button is clicked then do the following or else stop
3-Start with Categories.B2 which is the current total for Mortgage of $180 and add the amount from Budget.B2 of $90 to the $180 thus replacing Categories.B2 with the new sum of $270. Then move on to the next category item amount at Categories.B3 and add Budget.B3 to it, etc.
Do you see what I'm trying to do?
Thanks again!
I suspected that I didn't have a good understanding of the macro scripting.
Here's what I'm trying to do. I have a budget.
I have three sub-sheets within my spreadsheet.
1-Budget - How much each week needs to go into each Category
Category Weekly Amount
Mortgage $90
Internet $7.25
Cell Phone $20
etc..
2-More Info - account numbers, addresses, notes about bills, etc.
3-Categories - What is the current total in each Category
Categories Amount
Mortgage $180
Internet $14.50
Cell Phone $40
etc.
So I am trying to create a Button in the Category SubSheet that would do the following:
1-Are you sure you want to add a week's paycheck to each category?
Allow Yes or No response to user
2-If YES button is clicked then do the following or else stop
3-Start with Categories.B2 which is the current total for Mortgage of $180 and add the amount from Budget.B2 of $90 to the $180 thus replacing Categories.B2 with the new sum of $270. Then move on to the next category item amount at Categories.B3 and add Budget.B3 to it, etc.
Do you see what I'm trying to do?
Thanks again!
Open Office 4.1.1 on Windows 7
Re: Macro help on setvalue
Please, please UPLOAD your example .ods file 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.