VBA Drawing Help

emmcee

New Member
Joined
Sep 9, 2011
Messages
29
Hey guys, I'm trying to draw this 4 bar-linkage diagram from this link: http://s1113.photobucket.com/albums/k511/Emmcee1/?action=view&current=Untitled.jpg

This is the outline that I want from it:
' Create a new bar between (x1,y1) and (x2,y2) with a coupling at either end.
' Specify bar and coupling colours using Long constants or RGB(...) calls.
' You must save the result in a Shape variable if you want to move it later.

Function NewBar(ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double, _ ByVal lngBarColour As Long, ByVal lngCouplingColour As Long) As Shape

End Function


_____________________________________________________________

Somehow I tried doing this, but it wouldn't work like nothing pops up in the drawing when I click run. This is what i coded but it doesnt work:

Option Explicit

'
' Main subprogram is DrawFigure
' The first part (adding a sheet and removing grid and margin labels) is done for you
' The rest requires you to pick up parameters from named cells,
' to draw 4-bar linkage at specified location, and
' apply fills according to the parameter sheet.

' Cell names. Use wksParams.Range(NAME_CX) etc to obtain cell contents.

Const NAME_CX = "CentreX"
Const NAME_CY = "CentreY"

Sub DrawFigure()
' Local variables
Dim wksParams As Worksheet
Dim shp As Shape
Dim cx As Single, cy As Single

' Identify parameters sheet. Use wksParams.Range(...) rather than ActiveSheet
Set wksParams = Sheets("FigParams")

' Create new clean sheet, this becomes the active sheet
Sheets.Add

With ActiveWindow
.DisplayGridlines = False
.DisplayHeadings = False
End With

' Obtain positional parameters from the active sheet

cx = wksParams.Range(NAME_CX).Value
cy = wksParams.Range(NAME_CY).Value

End Sub

Function Aline(x As Single, y As Single) As Shape

Set Aline = ActiveSheet.Shapes.AddShape(msoShapeline, x, y)

End Function

Can anyone help me with another code that might work with this figure?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,588
Messages
6,179,743
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top