LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Can I use VBA to change name and controlsource

You mean each one by hand? Good luck!

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"hdf" wrote in message
oups.com...
On Mar 5, 8:34 pm, "Bob Phillips" wrote:
The problem is that just changing the names isn't preserved, you need to
do
it via Designer.

Something like this

Dim oVBProj As Object
Dim oVBComp As Object
Dim ctl As Control
Dim i As Long

Set oVBProj = ThisWorkbook.VBProject

On Error Resume Next

For Each oVBComp In oVBProj.VBComponents
If oVBComp.Type = 3 Then
For Each ctl In oVBComp.Designer.Controls
If TypeName(ctl) = "CheckBox" Then
i = i + 1
ctl.Name = "ChkBx_" & oVBComp.codemodule.Name & "_" &
i
ctl.ControlSource = "=A1" '"=ChkBx_" &
oVBComp.codemodule.Name & "_Link" & i
End If
Next
End If
Next

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"hdf" wrote in message

oups.com...

On Mar 5, 7:31 pm, "Bob Phillips" wrote:
Why would you not just set these as required in design mode?


--
---
HTH


Bob


I'm trying to avoid manually having to write the name and range name
in controlsource over and over 80 userforms x 20 chkboxes per form x 2
changes per userform.


By creating code I can simply create one set of instructions for the
first UserForm, use it once, then do a search and replace in the code
for the number (e.g. search for "Uf1" in the names called
"Uf1_name1...Uf1_name20" and Replace with "Uf2", etc.) and then run
the code again for the next UserForm and do this for each new
UserForm.


This would speed up the work a hundred fold, plus it avoids or limits
the chances for spelling errors.


Bob, thank you for your response. I don't really know what Designer
is and I'm afraid that what you suggest is way over my head and I
think it would be more prudent to do it the old fashion way.

Thanks none the less.

Hector



 
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
ControlSource and Localization Issue?? (run-time error '380' Could not set the ControlSource property) TCook Excel Programming 1 March 4th 07 08:12 AM
.ControlSource Ctech[_128_] Excel Programming 1 March 27th 06 01:16 PM
Change UserForm ControlSource with VBA [email protected] Excel Discussion (Misc queries) 2 February 24th 05 08:05 AM
Data Validation & ControlSource & Change event Ocker Excel Programming 4 November 5th 04 03:34 AM
Controlsource David Coleman Excel Programming 5 December 28th 03 01:14 PM


All times are GMT +1. The time now is 08:16 AM.

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

About Us

"It's about Microsoft Excel"