PDA

View Full Version : Solved: Command Buttons fire 'Runtime 438'



Juicey27
09-07-2010, 02:53 PM
Excel 2007 - VBA
Unable to get command buttons to fire properly
Currently have 4 command buttons that when I click on I receive "Run-time error '438' - Object doesn;t support this property or method." I have seperate spreadsheets within workbook per name - per button already setup. The properties Name also corresponds with name of each cmdbox
Code:
Private Sub cmdJCOX_Click()
Sheets("Main").OpenSheet "Joseph Cox"
End Sub
Private Sub cmdDOT_Click()
Sheets("Main").OpenSheet "Duffy O'Toole"
End Sub
Private Sub cmdCROWLAND_Click()
Sheets("Main").OpenSheet "Clinton Rowland"
End Sub
Private Sub cmdJROMANINI_Click()
Sheets("Main").OpenSheet "Joseph Romanini"
End Sub

Juicey27
09-07-2010, 02:54 PM
ALso, the 4 command buttons are grouped together on a seperate shee called MAIN.
Please help.

Aussiebear
09-07-2010, 03:29 PM
Try the following
Private Sub cmdJCOX_Click()
Sheets("Joseph Cox").Select
End Sub
Private Sub cmdDOT_Click()
Sheets("Duffy O'Toole").Select
End Sub
Private Sub cmdCROWLAND_Click()
Sheets("Clinton Rowland").Select
End Sub
Private Sub cmdJROMANINI_Click()
Sheets("Joseph Romanni").Select
End Sub

Juicey27
09-08-2010, 04:18 AM
Thank you very much Aussie.. Real quick, ne chance someone could decipher what I was doing wrong in the original code I posted with my question? Trying to learn something here!! Thanks again all!!!:bow:

Aussiebear
09-09-2010, 03:47 AM
I have never come across the opensheet command before. What version are you using? Ooops forget that last bit. If you are having an issue with syntax, sometimes its just as easy to go to Edit within the VBA window and turn on the List Properties/Methods option to find out as in this example what can attach with "Sheets". In this case its Sheets.select, however we also need to tell VBA which sheets to select hence the Sheets("Sheet Name").Select syntax

Juicey27
09-09-2010, 04:20 AM
That already makes things much more clearer. Thanks Aussie.