Arguments as properties

  • Thread starter Thread starter BruceD
  • Start date Start date
B

BruceD

I'm sure I'm doing this wrong, but I'm trying to use an
argument (variable) as a property:

Sub Test1()
ob1 = InputBox("Border: thin (1) or thick (2): ")
If ob1 = 1 Then ob1 = "xlThin"
If ob1 = 2 Then ob1 = "xlThick"
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = ob1
.ColorIndex = 1
End With
End Sub

I've used a MsgBox to confirm that ob1 is indeed set to
xlThick or xlThin, but I get run time error 1004 Unable
to set Weight property of the Border class.

Am I making a simple syntax error, or is this approach
not possible? Any help most greatfully appreciated!


BruceD
 
Bruce,

Get rid of the quotes around xlThin and xlThick.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Try:

Sub Test1()
ob1 = InputBox("Border: thin (1) or thick (2): ")
If ob1 = 1 Then ob1 = xlThin
If ob1 = 2 Then ob1 = xlThick
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = ob1
.ColorIndex = 1
End With
End Sub

--
If I've mis-understood the question please tell me.

HTH

ijb

Replies to group please

Not MCSD, MVP, TLA, P&P, PCMCIA, etc just trying to help
 
Just to add to the others. In Excel XP, xlThin has a value of 2, so you may
want to change your logic.

?xlThin
2

One of a few ways:

If ob1 = 1 Then
ob1 = "xlThin"
ElseIf ob1 = 2 Then
ob1 = "xlThick"
Else
' ??
End If


HTH
Dana DeLouis
 
Thanks to all who thought about this and answered!

Chip was right: getting rid of the quotes solved the
problem.

Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top