VBA error 91 creating elbow connector

Johnny C

Well-known Member
Joined
Nov 7, 2006
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

I've got a weird problem. I've got code to connect 2 shapes with an elbow connector using a function with start and end shape as parameters.
Code:
    Dim conlink as Shape
...other code
    conLink = AddElbowConnector(shpSourceSheetShape, shpTargetSheetShape)
Both shapes exist and the first time it connects them it works ok. The second time it tries to add a connector (it doesn't matter if there's multiple connectors connecting the 2 shapes) it crashes with this error and highlights the line above:
Code:
Run time error 91: Object variable or With block variable not set.
When I debug however and press F8 it steps into the function and the function works fine, it's the assignation of the shape the function returns that causes the problem.

I can get around it with an On Error Resume Next but I want to know why it's crashing.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I don't see any documentation on this function (AddElbowConnector) so I can only assume it is a function you created.
I can make some assumptions, but if none of this helps, you will need to post at least the first line of the function (with the arguments and returns).

My theories:
I suspect that the function is returning an object and thus you need to use set when assigning the variable.
Actually, since conLink is a Shape, it either HAS to return an object or else it isn't returning a shape at all.
My solution:
Rich (BB code):
Set conLink = AddElbowConnector(shpSourceSheetShape, shpTargetSheetShape)
 
Upvote 0
It may be that I need a set.
But it works the first time, it's the second time it crashes. Or it may be more, it adds a connection each time a condition for the second box is true. So maybe there's a maximum number of times you can add an elbow between 2 boxes.

Shapes are weird, you can have as many shapes as you want in a sheet with the same name, you can have a name as null but you can't connect a connector from a shape with a null name
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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