View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
michael.beckinsale michael.beckinsale is offline
external usenet poster
 
Posts: 274
Default Run another macro from within this macro

Hi Cathy,

Thats a lot more difficult but heres some code that l have amended
from Chip Pearsons site and most of the credit should go to him.

Everything in this is automatic, even the creation of the 'arrow
line'. Copy & paste the code into the sheet module (as described in my
earlier post) and assuming your 'tilt' value is in cell A1 everyr time
that value changes the existing arrow will be deleted and a new one
inserted at the correct angle. Assumes that 0 is vertical.

Rememebr to delete any existing lines / arrows you have. You will see
at the top of the code that there are some 'Const' variables that
determine the position & length of the arrow. I suggest you try as is
then see what happens when you change the values. Note the X & y
values are determined from the top left of the active sheet.

Hope this helps, let me know how you get on.

NOTE: (beware of word wrapping & commenting of posted code)

Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Range("$A$1") Then
'____________________________________________
'Change these values for position of arrow
'rotation point. Relates to postion from top
'left of document.
Const cCenterX As Single = 250
Const cCenterY As Single = 250
'____________________________________________
'Change this value for arrow length
Const cLenMinute As Single = 125
'____________________________________________
Const PI As Single = 3.14159265358979
Const TwoPI As Single = 2 * PI
Dim TiltValue As Integer
Dim LM As Shape
Dim LLM As LineFormat
Dim WS As Worksheet
Dim Theta As Single ' clockwise angle from vertical
Dim NewX As Single
Dim NewY As Single

On Error Resume Next

Set WS = ActiveSheet

WS.Shapes("LineMinute").Delete

'Create minute hand
Set LM = WS.Shapes.AddLine(beginx:=cCenterX, beginy:=cCenterY,
_
endx:=cCenterX, endy:=cCenterY -
cLenMinute)
Set LLM = LM.Line
LM.Name = "LineMinute"
LLM.EndArrowheadStyle = msoArrowheadTriangle
LLM.ForeColor.RGB = RGB(0, 0, 255)
LLM.Weight = 1.5
TiltValue = (Range("A1").Value) / 6
Theta = (TiltValue / 60) * TwoPI
NewX = cCenterX + (cLenMinute * Sin(Theta))
NewY = cCenterY - (cLenMinute * Cos(Theta))
LM.Nodes.SetPosition 2, NewX, NewY
End If
End Sub

Regards

Michael