[Solved] Change an Image Control's graphics via macro

Discuss the spreadsheet application
Post Reply
monkee09
Posts: 12
Joined: Tue Mar 10, 2015 3:29 pm

[Solved] Change an Image Control's graphics via macro

Post by monkee09 »

I have a Push Button (btnPush1) that calls a macro when clicked.
I have an Image Control (imgPic1) with Graphics set to "C:\A.gif".
It is anchored to Cell A1 (if that helps).
Both are on Sheet1.

I want the macro to change the Graphics on the Image Control to "C:\B.gif"
How would I achieve this?
Last edited by monkee09 on Mon Mar 21, 2016 9:39 pm, edited 1 time in total.
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change an Image Control's graphics via macro.

Post by Zizi64 »

Maybe it is easier to do this by make a trick: use two buttons (placed on same position), and control those visibility.


A tip:
You can get the pushed button in the assigned macro code:
viewtopic.php?f=45&t=35985
Last edited by Zizi64 on Sat Mar 19, 2016 8:08 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.
monkee09
Posts: 12
Joined: Tue Mar 10, 2015 3:29 pm

Re: Change an Image Control's graphics via macro.

Post by monkee09 »

That will not work for my purposes.
I need a macro that can access and change the Graphics property of an Image Control.
WindowsXP, OOo3.0.0
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change an Image Control's graphics via macro.

Post by Zizi64 »

Try this code. You need use LINKED pictures instead of the embedded ones.

Code: Select all

Sub ButtonClick(oEvent)
	Button = oEvent.Source
	
	'If (Not GlobalScope.BasicLibraries.isLibraryLoaded("XrayTool")) Then GlobalScope.BasicLibraries.LoadLibrary("XrayTool")
	'you can examine the control element by the Xray tool:
	
	'xray Button

	If Button.Model.ImageURL = "file:///C:/A.gif" then
		Button.Model.ImageURL = "file:///C:/B.gif"
	else
		Button.Model.ImageURL = "file:///C:/A.gif"
	end if

End Sub
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.
monkee09
Posts: 12
Joined: Tue Mar 10, 2015 3:29 pm

Re: Change an Image Control's graphics via macro.

Post by monkee09 »

This code successfully changes the image on the button clicked.
If I set the macro to be triggered by clicking on the Image Control, it toggles the image there as well.

But I need the event to be triggered from an event outside of the Image Control, as originally stated in the initial post.
The button is just a means to trigger the event from outside of the Image Control.

I need a macro that is called by a BUTTON, but changes the IMAGE CONTROL, as originally stated.
Two seperate objects. One calling a macro to change the other.
WindowsXP, OOo3.0.0
monkee09
Posts: 12
Joined: Tue Mar 10, 2015 3:29 pm

Re: Change an Image Control's graphics via macro.

Post by monkee09 »

Nevermind, I hunted further and found something close and adapted it to my needs.
In case anyone else would like the answer to this problem, the code is below:

Code: Select all

Sub ButtonClick(oEvent)

dim oButton
dim oForm
dim oImage
const sName="file:///C:/graphics/G1.GIF"

oButton=oEvent.source.model
oForm=oButton.parent
oImage=oForm.getbyname("imgPic")
oImage.imageurl=sName
oImage.reset

End Sub
WindowsXP, OOo3.0.0
ABRAR AHMED
Posts: 2
Joined: Wed Jun 13, 2018 9:34 am

Change Image using Push Button

Post by ABRAR AHMED »

Dear,
Please Let Me Know About Insert And Change Image Using Push Button

Please HELP

Thanks
Abrar
Thanks
Abrar
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
ABRAR AHMED
Posts: 2
Joined: Wed Jun 13, 2018 9:34 am

Re: [Solved] Change an Image Control's graphics via macro

Post by ABRAR AHMED »

Do You Have Any Video Tutorials Please Update
Thanks
Abrar
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Change an Image Control's graphics via macro

Post by Zizi64 »

Please read Andrew Pitonyak's free macro books.
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.
Post Reply