PDA

View Full Version : Sub - Optional arguments



balumail75
06-01-2013, 09:50 PM
Hi,

I created a sub with 5 parameters. In that 4 are optional parameters.

But if I pass the 2nd argument and leave next 3 arguments empty.

the last argument is allowing for empty argument. If I press space for the last one, it autoaligns and deletes the space, and gives the error message "Complie Error: Expected: expression"

the sub is -

Public Sub PositionandResize(shp As Shape, Optional sgTop As Single, Optional sgLeft As Single, Optional sgHeight As Single, Optional sgWidth As Single)

pass the arguments -
PositionandResize .Shapes(1), 115.4286, , ,

Please help for passing the last as empty argument.

Thanks for your help,
Balumail75.

Paul_Hossler
06-02-2013, 06:37 PM
I usually use Call

See if this would work for you


Call PositionandResize (.Shapes(1), 115.4286)


Otherwise, you'd need to use Named Parameters


PositionandResize shp:=.Shapes(1), sgTop:=115.4286




Paul

Aflatoon
06-07-2013, 04:37 AM
Since they are optional, simply don't pass them:
PositionandResize .Shapes(1), 115.4286