ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   R/T 1004 - Unable to get Button prop of Ws Class (https://www.excelbanter.com/excel-discussion-misc-queries/171341-r-t-1004-unable-get-button-prop-ws-class.html)

Jim May

R/T 1004 - Unable to get Button prop of Ws Class
 
I have a file (Sheet1 only used) with two Forms Command Buttons, with
Captions ToProtectWB and ToUnprotectWB. I want one to be enabled
and the other disabled according to the current setting. This is what I now
have **which is producing R/T 1004**. Can someone assist me?

Sub ToProtectWB()
'
ActiveWorkbook.Protect Password:="password", Structu=True,
Windows:=False
Sheets(1).Buttons("Protect WB").Enabled = False
Sheets(1).Buttons("Unprotect WB").Enabled = True
End Sub
Sub ToUnprotectWB()
'
ActiveWorkbook.Unprotect Password:="password"
Sheets(1).Buttons("Unprotect WB").Enabled = False
Sheets(1).Buttons("Protect WB").Enabled = True
End Sub

Bob Phillips

R/T 1004 - Unable to get Button prop of Ws Class
 
That means that the buttons are not named Protect WB and Unprotect WB.Select
them, and overwrite the names in the Names box.

Wouldn't it be better to make them visible/non-visible, as disabled has no
identifying features?

--
---
HTH

Bob


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



"Jim May" wrote in message
...
I have a file (Sheet1 only used) with two Forms Command Buttons, with
Captions ToProtectWB and ToUnprotectWB. I want one to be enabled
and the other disabled according to the current setting. This is what I
now
have **which is producing R/T 1004**. Can someone assist me?

Sub ToProtectWB()
'
ActiveWorkbook.Protect Password:="password", Structu=True,
Windows:=False
Sheets(1).Buttons("Protect WB").Enabled = False
Sheets(1).Buttons("Unprotect WB").Enabled = True
End Sub
Sub ToUnprotectWB()
'
ActiveWorkbook.Unprotect Password:="password"
Sheets(1).Buttons("Unprotect WB").Enabled = False
Sheets(1).Buttons("Protect WB").Enabled = True
End Sub




Jim May

R/T 1004 - Unable to get Button prop of Ws Class
 
Bob:
I changed the NameBox to agree with my Captions; Also went with your
suggestion to Hide versus disable. They are still not perfect. I am unable
to click each back and forth to acheive. I am maybe once or twice, but soon
there is no-response to my click. ???


Sub ToProtectWB()
'
ActiveWorkbook.Protect Password:="password", Structu=True,
Windows:=False
Sheets(1).Shapes("Protect WB").Visible = False
Sheets(1).Shapes("Unprotect WB").Visible = True
End Sub
Sub ToUnprotectWB()
'
ActiveWorkbook.Unprotect Password:="password"
Sheets(1).Shapes("Unprotect WB").Visible = False
Sheets(1).Shapes("Protect WB").Visible = True
End Sub

"Bob Phillips" wrote:

That means that the buttons are not named Protect WB and Unprotect WB.Select
them, and overwrite the names in the Names box.

Wouldn't it be better to make them visible/non-visible, as disabled has no
identifying features?

--
---
HTH

Bob


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



"Jim May" wrote in message
...
I have a file (Sheet1 only used) with two Forms Command Buttons, with
Captions ToProtectWB and ToUnprotectWB. I want one to be enabled
and the other disabled according to the current setting. This is what I
now
have **which is producing R/T 1004**. Can someone assist me?

Sub ToProtectWB()
'
ActiveWorkbook.Protect Password:="password", Structu=True,
Windows:=False
Sheets(1).Buttons("Protect WB").Enabled = False
Sheets(1).Buttons("Unprotect WB").Enabled = True
End Sub
Sub ToUnprotectWB()
'
ActiveWorkbook.Unprotect Password:="password"
Sheets(1).Buttons("Unprotect WB").Enabled = False
Sheets(1).Buttons("Protect WB").Enabled = True
End Sub





Bob Phillips

R/T 1004 - Unable to get Button prop of Ws Class
 
Worked fine for me Jim, unremittingly.

Here is an alternative suggestion, just one button called Protect WB, assign
the ToProtectWB macro

Sub ToProtectWB()
'
With Sheets(1).Buttons("Protect WB")
If .Caption = "Protect WB" Then
.Caption = "Unprotect WB"
ActiveWorkbook.Protect Password:="password", Structu=True,
Windows:=False
Else
ActiveWorkbook.Unprotect Password:="password"
.Caption = "Protect WB"
End If
End With
End Sub


--
---
HTH

Bob


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



"Jim May" wrote in message
...
Bob:
I changed the NameBox to agree with my Captions; Also went with your
suggestion to Hide versus disable. They are still not perfect. I am
unable
to click each back and forth to acheive. I am maybe once or twice, but
soon
there is no-response to my click. ???


Sub ToProtectWB()
'
ActiveWorkbook.Protect Password:="password", Structu=True,
Windows:=False
Sheets(1).Shapes("Protect WB").Visible = False
Sheets(1).Shapes("Unprotect WB").Visible = True
End Sub
Sub ToUnprotectWB()
'
ActiveWorkbook.Unprotect Password:="password"
Sheets(1).Shapes("Unprotect WB").Visible = False
Sheets(1).Shapes("Protect WB").Visible = True
End Sub

"Bob Phillips" wrote:

That means that the buttons are not named Protect WB and Unprotect
WB.Select
them, and overwrite the names in the Names box.

Wouldn't it be better to make them visible/non-visible, as disabled has
no
identifying features?

--
---
HTH

Bob


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



"Jim May" wrote in message
...
I have a file (Sheet1 only used) with two Forms Command Buttons, with
Captions ToProtectWB and ToUnprotectWB. I want one to be enabled
and the other disabled according to the current setting. This is what I
now
have **which is producing R/T 1004**. Can someone assist me?

Sub ToProtectWB()
'
ActiveWorkbook.Protect Password:="password", Structu=True,
Windows:=False
Sheets(1).Buttons("Protect WB").Enabled = False
Sheets(1).Buttons("Unprotect WB").Enabled = True
End Sub
Sub ToUnprotectWB()
'
ActiveWorkbook.Unprotect Password:="password"
Sheets(1).Buttons("Unprotect WB").Enabled = False
Sheets(1).Buttons("Protect WB").Enabled = True
End Sub








All times are GMT +1. The time now is 08:51 PM.

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