Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Name Check Box in code

Hi,

Does anyone know how to name a Check Box in code while creating the box?
Im using a WITH statement and .NAME. This is on an Excel Sheet.

Here is the code:
Sub CreateDropDownBox()
' Create Drop Down Box
Dim DropDown

With Worksheets(1).Shapes.AddFormControl(xlDropDown, _
Left:=150, Top:=10, Width:=100, Height:=10)
.ControlFormat.DropDownLines = 10
.Name = DropDown

End With
ActiveSheet.DropDowns.Select
With Selection
.ListFillRange = "$C$1:$C$6"
.LinkedCell = ""
.DropDownLines = 8
.Display3DShading = False
End With
End Sub

The €˜.Name = DropDown returns €˜The specific value is out of range error
statement.

Any help will be appreciated.

Thanks
Paul

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Name Check Box in code

I think all you forgot was the quotes:
With Worksheets(1).Shapes.AddFormControl(xlDropDown, _
Left:=150, Top:=10, Width:=100, Height:=10)
.ControlFormat.DropDownLines = 10
.Name = "DropDown"


"Paul" wrote:

Hi,

Does anyone know how to name a Check Box in code while creating the box?
Im using a WITH statement and .NAME. This is on an Excel Sheet.

Here is the code:
Sub CreateDropDownBox()
' Create Drop Down Box
Dim DropDown

With Worksheets(1).Shapes.AddFormControl(xlDropDown, _
Left:=150, Top:=10, Width:=100, Height:=10)
.ControlFormat.DropDownLines = 10
.Name = DropDown

End With
ActiveSheet.DropDowns.Select
With Selection
.ListFillRange = "$C$1:$C$6"
.LinkedCell = ""
.DropDownLines = 8
.Display3DShading = False
End With
End Sub

The €˜.Name = DropDown returns €˜The specific value is out of range error
statement.

Any help will be appreciated.

Thanks
Paul

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Name Check Box in code

Hi Paul,

It should be
DropDown = .Name since want to read the name and assing it to variable
DropDown.
And NOT
..Name = Dropdown cause this mean you are trying to set the name and
since Varibale DropDown is empty, it is giving error.

Sharad

"Paul" wrote in message
...
Hi,

Does anyone know how to name a Check Box in code while creating the box?
I'm using a WITH statement and .NAME. This is on an Excel Sheet.

Here is the code:
Sub CreateDropDownBox()
' Create Drop Down Box
Dim DropDown

With Worksheets(1).Shapes.AddFormControl(xlDropDown, _
Left:=150, Top:=10, Width:=100, Height:=10)
.ControlFormat.DropDownLines = 10
.Name = DropDown

End With
ActiveSheet.DropDowns.Select
With Selection
.ListFillRange = "$C$1:$C$6"
.LinkedCell = ""
.DropDownLines = 8
.Display3DShading = False
End With
End Sub

The '.Name = DropDown' returns 'The specific value is out of range' error
statement.

Any help will be appreciated.

Thanks
Paul



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Name Check Box in code

Paul,

This works for me

Sub CreateDropDownBox()
' Create Drop Down Box
Dim DropDown

With Worksheets(1).Shapes
Set DropDown = .AddFormControl(xlDropDown, _
Left:=150, Top:=10, Width:=100, Height:=10)
End With

With DropDown
.Name = "myDropdown"
With .ControlFormat
.DropDownLines = 10
.ListFillRange = "$C$1:$C$6"
.LinkedCell = ""
End With
.DrawingObject.Display3DShading = False
End With
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Paul" wrote in message
...
Hi,

Does anyone know how to name a Check Box in code while creating the box?
I'm using a WITH statement and .NAME. This is on an Excel Sheet.

Here is the code:
Sub CreateDropDownBox()
' Create Drop Down Box
Dim DropDown

With Worksheets(1).Shapes.AddFormControl(xlDropDown, _
Left:=150, Top:=10, Width:=100, Height:=10)
.ControlFormat.DropDownLines = 10
.Name = DropDown

End With
ActiveSheet.DropDowns.Select
With Selection
.ListFillRange = "$C$1:$C$6"
.LinkedCell = ""
.DropDownLines = 8
.Display3DShading = False
End With
End Sub

The '.Name = DropDown' returns 'The specific value is out of range' error
statement.

Any help will be appreciated.

Thanks
Paul



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Name Check Box in code

I don't think I would use DropDown as my variable name. That's a name of a
control that excel uses.

And you can still work with the dropdown directly--instead of going through the
shapes collection:

Option Explicit
Sub CreateDropDownBox()

Dim MyDropDown As DropDown

With Worksheets(1)
Set MyDropDown = .DropDowns.Add _
(Left:=150, Top:=10, _
Width:=100, Height:=10)
End With

With MyDropDown
.Name = "dd_" & .TopLeftCell.Address(0, 0)
.ListFillRange = .Parent.Range("c1:c6").Address(external:=True)
.DropDownLines = 8
.Display3DShading = False
End With

End Sub




Paul wrote:

Hi,

Does anyone know how to name a Check Box in code while creating the box?
Im using a WITH statement and .NAME. This is on an Excel Sheet.

Here is the code:
Sub CreateDropDownBox()
' Create Drop Down Box
Dim DropDown

With Worksheets(1).Shapes.AddFormControl(xlDropDown, _
Left:=150, Top:=10, Width:=100, Height:=10)
.ControlFormat.DropDownLines = 10
.Name = DropDown

End With
ActiveSheet.DropDowns.Select
With Selection
.ListFillRange = "$C$1:$C$6"
.LinkedCell = ""
.DropDownLines = 8
.Display3DShading = False
End With
End Sub

The €˜.Name = DropDown returns €˜The specific value is out of range error
statement.

Any help will be appreciated.

Thanks
Paul


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Box - Macro code Vicky Excel Discussion (Misc queries) 2 March 17th 09 08:28 AM
Please check my code!!!! Tdp Excel Discussion (Misc queries) 1 October 27th 08 02:39 PM
Please check my code? Rich[_25_] Excel Programming 2 October 27th 04 07:12 AM
Please help (need a code check) Aaron Cooper Excel Programming 5 April 9th 04 05:56 PM
Check Box Code Bob Excel Programming 3 January 14th 04 06:07 AM


All times are GMT +1. The time now is 10:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"