Adding buttons and connect macro

B

Bob Phillips

Lars,

I do not what code you have to zoom in and out, but all you need is a simple
Boolean variable to determine whether its small or large diagram.

Something like

Dim fDiagram1 as Boolean
Dim fDiagram2 As Boolean
etc.

Sub Zoom()

If fDiagram1 = True Then
Call ZoomOutDiagram1
Else
Call ZoomInDaigram1
End If

fDiagram1 = Not fDiagram1

End Sub

Get the idea?
 
L

Lars Peter Nielsen

Hi

First of all I will le´t you know I am from Denmark, so I am sry. about my
english.

Here is what I have made: I have this workbook whith up to 10 sheets. On
each sheet I have 4 diagrams fitted so I can see them at once. Then I have
made macros, so when I click on a diagram it will zoom out, so this
particular diagram fits the whole screen (so you can see details better).
Also made macros, so when I run it, the diagrams zooms back in (back to
start - with all 4 diagrams at the same place).

What I need is when I click on 1 diagram and zooms out - the code should
also create a button whit my zoom in macro, so when I click on that one it
will zoom back. If this is possible I also need the code to delete the
button, which I could put into my zoom in macro.

Maybe there is an easier way, pls. let me know. I was thinking, maybe it was
possible to create the macro, so when I click on the diagram and it zooms
out, then the macro change on the diagram, so next time when I click on it -
it zooms in (run my zoom in macro).

I dont know if you understand my problem.

Regards

Lars
 
B

Bob Phillips

Lars,

Yes it will work, just need to adapt to suit. It would go something like

Dim fDiagram1 as Boolean
Dim fDiagram2 As Boolean
etc.

Sub Zoom()

fDiagram1 = ZoomDiagram(1, fDiagram1)

fdiagram2 = ZoomDiagram(2, fdiagram2)

'etc.

End Sub


Function ZoomDiagram(Diagram As Long, ZoomIn As Boolean) As Boolean

With ActiveSheet.Shapes("Diagram" & Diagram)
If ZoomIn Then
.ScaleWidth 1.61, msoFalse, msoScaleFromTopLeft
Else
.ScaleHeight 1.39, msoFalse, msoScaleFromTopLeft
End If
End With

ActiveWindow.Visible = False

Range("I29").Select

ZoomDiagram = Not ZoomIn

End Function

This will work from any sheet as long as it is the activesheet, and as long
as the Diaghrams are all called Daigram 1, Diagram 2, etc, whatever the
sheet.
 
L

Lars Peter Nielsen

Thx. I will try to make it work...

LPN


Bob Phillips said:
Lars,

Yes it will work, just need to adapt to suit. It would go something like

Dim fDiagram1 as Boolean
Dim fDiagram2 As Boolean
etc.

Sub Zoom()

fDiagram1 = ZoomDiagram(1, fDiagram1)

fdiagram2 = ZoomDiagram(2, fdiagram2)

'etc.

End Sub


Function ZoomDiagram(Diagram As Long, ZoomIn As Boolean) As Boolean

With ActiveSheet.Shapes("Diagram" & Diagram)
If ZoomIn Then
.ScaleWidth 1.61, msoFalse, msoScaleFromTopLeft
Else
.ScaleHeight 1.39, msoFalse, msoScaleFromTopLeft
End If
End With

ActiveWindow.Visible = False

Range("I29").Select

ZoomDiagram = Not ZoomIn

End Function

This will work from any sheet as long as it is the activesheet, and as long
as the Diaghrams are all called Daigram 1, Diagram 2, etc, whatever the
sheet.

--

HTH

Bob Phillips

sheets. maybe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top