Solved

Rotating a line shape about a point.

Posted on 2011-09-28
10
1,868 Views
Last Modified: 2012-05-12
I'm trying to rotate a line shape (created with the Shapes.AddLine method) about a point.
I've found an example authored by Chip Pearson - a clock - that does this nicely. It uses the following code to move the second hand:

 
Private Sub SetSecondHand(Seconds As Single)
Dim Theta As Single ' clockwise angle from vertical
Dim NewX As Single
Dim NewY As Single
Dim LS as Shape
Theta = (Seconds / 60) * TwoPI
NewX = cCenterX + (cLenSecond * Sin(Theta))
NewY = cCenterY - (cLenSecond * Cos(Theta))

LS.Nodes.SetPosition 2, NewX, NewY

Open in new window


However, when I try to run this code in Excel 2010, it returns the following error message:

"The specified value is out of range"

(Variables NewX = 296 and NewY = 107)

I've attached the original source file. Can you assist me in getting this to work on the newer version of Excel? Clock.xls
0
Comment
Question by:dsimcox
  • 5
  • 5
10 Comments
 

Author Comment

by:dsimcox
ID: 36718117
A little more investigation - the shape Chip created (in an older version of Excel) with the Shape.AddLine method has no nodes in the newer versions of Excel. LS.Nodes.Count yields 0. If I create a free-form shape, it has a positive node count. Apparently the lines created with Shape.AddLine are different and node-less.
0
 
LVL 19

Expert Comment

by:akoster
ID: 36813484
The problem is that from excel 2007 the nodes property is no longer used and instead the rotation property is promoted.

let me see if i can come up with a solution...
0
 
LVL 19

Accepted Solution

by:
akoster earned 500 total points
ID: 36813503
this indeed works with polylines.
In order for the text fields to work, i updated the initialising code a little.
Clock.xls
0
 

Author Comment

by:dsimcox
ID: 36814287
I've worked with the rotation property - but it rotates about the center point of the line. I want to rotate the line about the end point.

I think the nodes property is still accessible. If you draw a free-form line and check for nodes in the immediate window, it returns the correct answer - but not for a autoshape.
0
 
LVL 19

Expert Comment

by:akoster
ID: 36814562
dsimcox, have you tried the updated version of the clock.xls file ?

it uses polylines instead of lines. With polylines (which do have node objects accessible) the clock lines indeed can be pointed 'in the right direction' using macro code.
The version that I uploaded works at my workplace, using excel 2007.

Can you verify that it also works at your location ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:dsimcox
ID: 36819044
I'd like to try the newer version of clocks.xls but I don't know where to find it. Can you post a link please?
0
 
LVL 19

Expert Comment

by:akoster
ID: 36891293
it's in my post 36813503 of september 29th @ 10.28 AM
you can click on the underlined text clock.xls
0
 

Author Comment

by:dsimcox
ID: 36896352
Great - I'm out of town until Monday so I'll have a look at it then. Thanks for your helpful reply!
0
 

Author Comment

by:dsimcox
ID: 36963655
I was able to use this example to get my code working. Thanks for making the updates to Chip's code. It helped a lot!
0
 
LVL 19

Expert Comment

by:akoster
ID: 36964353
you're welcome !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now