Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with vba and command button

Hi, I have a macro called create_report
I would like to insert this in a command button. I want the comman
button to only be clicked once when the sheet is open, and it should b
disabled afterwards. So, if the sheet is closed and reopened, th
button should work once and then be disabled. I have the following
it's not making my button work at all:

Private Sub CommandButton1_Click()
Create_Report
CommandButton1.Enabled = False
End Sub


Please help.


richard

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default help with vba and command button

Have you put the code in the worksheet code module?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"RichardO " wrote in message
...
Hi, I have a macro called create_report
I would like to insert this in a command button. I want the command
button to only be clicked once when the sheet is open, and it should be
disabled afterwards. So, if the sheet is closed and reopened, the
button should work once and then be disabled. I have the following,
it's not making my button work at all:

Private Sub CommandButton1_Click()
Create_Report
CommandButton1.Enabled = False
End Sub


Please help.


richardo


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default help with vba and command button

Hi Richard

You can have the workbook_open event fire to re-enable your command button each time. For example, assuming your button is on "Sheet1" you could have code like the following store in the "ThisWorkbook" code module

Private Sub Workbook_Open(
Sheet1.CommandButton1.Enabled = Tru
End Su

The other existing code you have would do the job and then disable the button. This would re-enable the button whenever the workbook was opened

-Gen


----- RichardO wrote: ----

Hi, I have a macro called create_repor
I would like to insert this in a command button. I want the comman
button to only be clicked once when the sheet is open, and it should b
disabled afterwards. So, if the sheet is closed and reopened, th
button should work once and then be disabled. I have the following
it's not making my button work at all

Private Sub CommandButton1_Click(
Create_Repor
CommandButton1.Enabled = Fals
End Su


Please help


richard


--
Message posted from http://www.ExcelForum.com


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with vba and command button

Yes, my code is in the worksheet code module.

Thanks, Richardo

Bob Phillips wrote:
*Have you put the code in the worksheet code module?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"RichardO " wrote i
message
...
Hi, I have a macro called create_report
I would like to insert this in a command button. I want th

command
button to only be clicked once when the sheet is open, and i

should be
disabled afterwards. So, if the sheet is closed and reopened, the
button should work once and then be disabled. I have th

following,
it's not making my button work at all:

Private Sub CommandButton1_Click()
Create_Report
CommandButton1.Enabled = False
End Sub


Please help.


richardo


---
Message posted from http://www.ExcelForum.com/


--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with vba and command button

Hi Gene,

I tried that, it disabled the command button after running the cod
once. Then I closed the file, re-opened it, but the button i
disabled, I can't run the code again. The reason why I want th
button to work when I reopen the file is because I made use of the fil
everyday, but then I save it as another name and then work on it.

How do I modify the code so that when I reopen my excel workbook, th
button is enabled.

This is the code I used when I clicked ThisWorkbook:

Private Sub Workbook_Open()
Sheet1.CommandButton1.Enabled = True
End Sub

This is the macro to run the report in sheet 2 because my data is i
sheet 2:

Private Sub CommandButton1_Click()
Create_Report
CommandButton1.Enabled = False
End Sub

Thanks,


Richardo




~× wrote:
*Hi Richard,

You can have the workbook_open event fire to re-enable your comman
button each time. For example, assuming your button is on "Sheet1
you could have code like the following store in the "ThisWorkbook
code module.

Private Sub Workbook_Open()
Sheet1.CommandButton1.Enabled = True
End Sub

The other existing code you have would do the job and then disabl
the button. This would re-enable the button whenever the workbook wa
opened.

-Gene


----- RichardO wrote: -----

Hi, I have a macro called create_report
I would like to insert this in a command button. I want the command
button to only be clicked once when the sheet is open, and it shoul
be
disabled afterwards. So, if the sheet is closed and reopened, the
button should work once and then be disabled. I have the following,
it's not making my button work at all:

Private Sub CommandButton1_Click()
Create_Report
CommandButton1.Enabled = False
End Sub


Please help.


richardo


---
Message posted from http://www.ExcelForum.com/


--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with vba and command button

Hi Gene:

I tried all 3 points. the applications.enableevents= true
My code was saved, and it was saved in sheet2, because my button is in
sheet 2. so I changed the thisworkbook code from:

Private Sub Workbook_Open()
Sheet1.CommandButton1.Enabled = True
End Sub

to

Private Sub Workbook_Open()
Sheet2.CommandButton1.Enabled = True
End Sub

But it's still not activating the button. I also changed the "code
name", same thing.

I don't mind taking a look at the macro you set up. Please send it to:


Thanks.

Richardo


---
Message posted from
http://www.ExcelForum.com/

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 sub Atishoo Excel Discussion (Misc queries) 3 February 11th 09 04:50 PM
command button add another command Wanna Learn Excel Discussion (Misc queries) 5 December 7th 08 11:42 PM
Command Button vs Control Button RGibson Excel Programming 1 October 14th 03 02:24 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM
command button George[_15_] Excel Programming 5 August 9th 03 11:49 AM


All times are GMT +1. The time now is 04:58 PM.

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"