Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code created in a Macro not working for a Command Button


Ok...I created a macro to give me a head start with a command button. I
need the VBA coding to select all the cells on a given worksheet. The
macro used:

Cells.Select

All sources I have seen so far indicate that this should be correct,
however, once the code was copied from the macro to the command button
I keep getting the following error:

Run-time error '1004':
Select method of Range class failed.

So, why on earth does it work in the macro, and not for the command
button?
Any ideas?

Thanks,
Amber :)


--
Amber_D_Laws
------------------------------------------------------------------------
Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
View this thread: http://www.excelforum.com/showthread...hreadid=500357

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Code created in a Macro not working for a Command Button

Hi Amber

Do you use Excel 97 ?

Change the takefocusonclick in the properties of the button to false

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Amber_D_Laws" wrote in message
news:Amber_D_Laws.21hlay_1137010503.0178@excelforu m-nospam.com...

Ok...I created a macro to give me a head start with a command button. I
need the VBA coding to select all the cells on a given worksheet. The
macro used:

Cells.Select

All sources I have seen so far indicate that this should be correct,
however, once the code was copied from the macro to the command button
I keep getting the following error:

Run-time error '1004':
Select method of Range class failed.

So, why on earth does it work in the macro, and not for the command
button?
Any ideas?

Thanks,
Amber :)


--
Amber_D_Laws
------------------------------------------------------------------------
Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
View this thread: http://www.excelforum.com/showthread...hreadid=500357



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code created in a Macro not working for a Command Button


No luck. I tried your suggestion, and it had no effect.
I am using Excel 2000.
Eventhought your suggestion did not work, thanks for trying! :)


--
Amber_D_Laws
------------------------------------------------------------------------
Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
View this thread: http://www.excelforum.com/showthread...hreadid=500357

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Code created in a Macro not working for a Command Button

Hi Amber

If you want you can send me the workbook private then I look at it for you

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Amber_D_Laws" wrote in message
news:Amber_D_Laws.21hm8c_1137011704.9758@excelforu m-nospam.com...

No luck. I tried your suggestion, and it had no effect.
I am using Excel 2000.
Eventhought your suggestion did not work, thanks for trying! :)


--
Amber_D_Laws
------------------------------------------------------------------------
Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
View this thread: http://www.excelforum.com/showthread...hreadid=500357



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code created in a Macro not working for a Command Button


Thanks Ron,

I really appreciate the offer. It is a quote module for my company, I
will show you the code here, and if you are not able to puzzle it out
from there, I will email the file to you.
It has a whole lot of password protection on it, confidential
information, and it's really big. So, I am sure you can see why I am
reticent about sending it.

Here is the code:


Code:
--------------------

Private Sub CommandButton2_Click()
'Makes the quote email ready
'
'
'Prep 1 - Declares the variables for the file name to be used in the "saved as" function
Dim QNum As String
Dim CNam As String
Dim CrDt As String
Dim VNum As String
'
'Prep 2 - Defines the variable names from Quote Form
QNum = Range("X10").Text
CNam = Range("O19").Text
CrDt = Format(Now, "mmddyy")
VNum = Range("AB10").Text
'
'Step 1 - Save, and hide all non-essential sheets
ActiveWorkbook.Save
ActiveWindow.SelectedSheets.Visible = False
ActiveWindow.SelectedSheets.Visible = False
ActiveWindow.SelectedSheets.Visible = False
'
'Step 2 - Locks all cells, hides user notes, and re-hides the column and row headings
ActiveWindow.DisplayHeadings = True
ActiveSheet.Unprotect Password:="STLMOB@900"
Cells.Select
Selection.Locked = True
Selection.FormulaHidden = False
Columns("AD:AI").Select
Range("AI1").Activate
Selection.EntireColumn.Hidden = True
ActiveWindow.DisplayHeadings = False
'
'Step 3 - Protects the worksheet and workbook
ActiveSheet.Protect Password:="STLMOB@900", DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoSelection
ActiveWorkbook.Protect Password:="STLMOB@900", Structu=True, Windows:=False
'
'Step 4 - Saves the protected file with a unique name, and makes it read-only recommended
ActiveWorkbook.SaveAs Filename:= _
"X:\_FEE SCHEDULE & QUOTE MODULE\Created Quotes\" _
& QNum & "-" & CNam & "-" & CrDt & " _ver " & VNum & " - EMAIL" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="STLMOB@900", _
ReadOnlyRecommended:=True, CreateBackup:=False
'
'Step 5 - Displays a message informing the user that the protection is complete
MsgBox "Your quote has been successfully protected." & _
Chr(13) & "It is now safe to email.", 64, "Security Check Complete!"
End Sub
--------------------


--
Amber_D_Laws
------------------------------------------------------------------------
Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
View this thread: http://www.excelforum.com/showthread...hreadid=500357



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code created in a Macro not working for a Command Button


I forgot to tell you where to look, and exactly what I am trying to get
the thing to do. Sorry.

This button is supposed to protect the file and lock it up the file so
that the client my user will be sending the file to can look at it and
print it, but nothing else.
My problem is in step 2 where on the "QUOTE" sheet itself, I am hiding
some user notes, and locking cells that were previously unlocked. This
is where I have the attempt to select all the cells that is giving me
the run-time error.

As I mentioned previously, I created the macro, edited it with a few
extras you can't get from macro recording, and tested it by running the
macro. It worked like a charm. My problem started when I transfered that
coding into the sub for the command button.

Thanks again Ron. :)


--
Amber_D_Laws
------------------------------------------------------------------------
Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
View this thread: http://www.excelforum.com/showthread...hreadid=500357

Reply
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
command button isn't working Nydia New Users to Excel 1 April 29th 05 10:31 PM
How do I assign a macro I have created to a Command Button in Exc. Andrew7675 Excel Discussion (Misc queries) 1 March 3rd 05 08:08 PM
macro code doesnt work in command button The Grinch[_9_] Excel Programming 4 July 22nd 04 06:28 PM
Disabling/enabling events with a button created by code?? Simon Lloyd[_518_] Excel Programming 5 July 7th 04 12:09 PM
Non Working Cells after command button rlgh60 Excel Programming 1 November 6th 03 11:01 PM


All times are GMT +1. The time now is 12:00 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"