ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Apply vba code to multiple userform objects (https://www.excelbanter.com/excel-programming/315872-apply-vba-code-multiple-userform-objects.html)

sjoopie[_2_]

Apply vba code to multiple userform objects
 

Thanks for the help,

on the following line:

ctl.BackStyle = fmBackStyleOpaque

i receive error message 43

--
sjoopi
-----------------------------------------------------------------------
sjoopie's Profile: http://www.excelforum.com/member.php...fo&userid=1611
View this thread: http://www.excelforum.com/showthread.php?threadid=27557


Nikos Yannacopoulos[_5_]

Apply vba code to multiple userform objects
 
That's because you are trying to set the backstyle property of a control
that doesn't have one, such as a command button, for instance. You need to
make some provision in your code to set the property of the desired controls
only. Looking at the names of the controls in your first post, it looks like
the following could work:

For Each ctl In ProjectenForm.Controls
If Left(ctl.Name, 2) = "Eg" Or Left(ctl.Name, 2) = "Mg" Then
ctl.BackStyle = fmBackStyleOpaque
End If
Next

provided that the name of the control causing the error doesn't start with
Eg or Mg.

HTH,
Nikos

"sjoopie" wrote in message
...

Thanks for the help,

on the following line:

ctl.BackStyle = fmBackStyleOpaque

i receive error message 438


--
sjoopie
------------------------------------------------------------------------
sjoopie's Profile:

http://www.excelforum.com/member.php...o&userid=16110
View this thread: http://www.excelforum.com/showthread...hreadid=275576




Bob Phillips[_6_]

Apply vba code to multiple userform objects
 
Or test the control type

For Each ctl In ProjectenForm.Controls
If Typename(ctl) = "TextBox" Then
ctl.BackStyle = fmBackStyleOpaque
End If
Next


--

HTH

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


"Nikos Yannacopoulos" wrote in message
...
That's because you are trying to set the backstyle property of a control
that doesn't have one, such as a command button, for instance. You need to
make some provision in your code to set the property of the desired

controls
only. Looking at the names of the controls in your first post, it looks

like
the following could work:

For Each ctl In ProjectenForm.Controls
If Left(ctl.Name, 2) = "Eg" Or Left(ctl.Name, 2) = "Mg" Then
ctl.BackStyle = fmBackStyleOpaque
End If
Next

provided that the name of the control causing the error doesn't start with
Eg or Mg.

HTH,
Nikos

"sjoopie" wrote in message
...

Thanks for the help,

on the following line:

ctl.BackStyle = fmBackStyleOpaque

i receive error message 438


--
sjoopie
------------------------------------------------------------------------
sjoopie's Profile:

http://www.excelforum.com/member.php...o&userid=16110
View this thread:

http://www.excelforum.com/showthread...hreadid=275576







All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com