How can i Enable/Disable CommandButtons from Wkbook Open event ???

C

Coza

Private Sub Workbook_Open()
Sheets("Intro").Activate
With Application
MsgBox "Welcome " & "*** " & .UserName & " ***" & " to the Tracker
File.", vbInformation
End With
If Sheets("Data").Range("A1").Value = "" Then
CommandButton1.Enabled = False
Else
CommandButton1.Enabled = True
End If
End Sub

The above code returns a Compile error.

How can i get it to work?

Corey....
 
D

Dave Peterson

Is that commandbutton on the Intro sheet or the Data sheet?

I'm guessing Intro:

Option Explicit
Private Sub Workbook_Open()
With Sheets("Intro")
.Select
MsgBox "Welcome " & "*** " & Application.UserName _
& " ***" & " to the Tracker File.", vbInformation

If Sheets("Data").Range("A1").Value = "" Then
.CommandButton1.Enabled = False
Else
.CommandButton1.Enabled = True
End If
End With
End Sub

Notice the dots in front of .commandbutton1. This means that it belongs to the
object in the previous With statement--in this case the Intro sheet.
 

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

Top