Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Make a Cell Act like a Button

I am building a worksheet that builds four database queries that will be
copied and pasted into the DBMS for now. About 80% of each of these queries
never changes, so I use 4 sheets to hold those static elements. The first
sheet of the worksheet contains a zip code and a varying number of streets.
That number of streets determines how long each query string will be. With
10 streets, the queries are 35, 44, 56 and 107 lines long.

Each query has a title cell as the first line that is just there to label
the query. And there are several empty rows separating each query.
Everything in the query is, including the title, in column A.

I want to make a button that will select and copy the query. I have recorded
a macro that will work just fine. I just need to know what to do to turn a
cell into a button, since the macro should do the rest.

What event do I need to trap? And what object to I put that event handler
in?

Also, once I figure that out, I need to know how to add that event handler
to the sheet as I build the queries.

My thinking is:

Add the query label
move over three cells and Add the button
move back three cells and down one row and Build the query

Then do the same thing again for the next three queries.

I know I got kind of wordy here, but I hope someone can point me in the
right direction.

Thanks,
Ken Loomis







  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Make a Cell Act like a Button

Hello Ken,

Excel buttons are part of the Shapes collection which belongs to the
worksheet as a separate layer but not as range (cell) property. Here's a
prototype of a meta code that is supposed to do exactly what you need.


dim shp as Shape
shp = ws.Shapes.AddFormControl(XlFormControl.xlButtonCon trol,
rng.Left,
rng.Top,
rng.Width,
rng.Height)


shp.OnAction = "MyMacroSub"
shp.TextFrame ... here set the button title
shp.Select

Note that rng represent the cell boundaries over which the button will
appear and ws is your button worksheet.

The details related to your application you will be able to tackle with
yourself.

HTH,
Nacho



"Ken Loomis" wrote in message
...
I am building a worksheet that builds four database queries that will be
copied and pasted into the DBMS for now. About 80% of each of these

queries
never changes, so I use 4 sheets to hold those static elements. The first
sheet of the worksheet contains a zip code and a varying number of

streets.
That number of streets determines how long each query string will be. With
10 streets, the queries are 35, 44, 56 and 107 lines long.

Each query has a title cell as the first line that is just there to label
the query. And there are several empty rows separating each query.
Everything in the query is, including the title, in column A.

I want to make a button that will select and copy the query. I have

recorded
a macro that will work just fine. I just need to know what to do to turn a
cell into a button, since the macro should do the rest.

What event do I need to trap? And what object to I put that event handler
in?

Also, once I figure that out, I need to know how to add that event handler
to the sheet as I build the queries.

My thinking is:

Add the query label
move over three cells and Add the button
move back three cells and down one row and Build the query

Then do the same thing again for the next three queries.

I know I got kind of wordy here, but I hope someone can point me in the
right direction.

Thanks,
Ken Loomis









  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Make a Cell Act like a Button

Hi Ken

You can use almost anything but a cell for this.
Display the "Drawing" toolbar (View Toolbars menu). Put one object from it
onto your sheet, say an Autoshape or a Textbox.
Rightclick it, choose "Assign macro" and assign your macro.

Now your mousepointer turns to a hand cursor over this object, and clicking
it rund the macro. Make the object look good (text, color, ... )

You can also use a button from the Form toolbar if you want something more
button-like. Same procedure as above.

HTH. best wishes Harald

"Ken Loomis" skrev i melding
...
I am building a worksheet that builds four database queries that will be
copied and pasted into the DBMS for now. About 80% of each of these

queries
never changes, so I use 4 sheets to hold those static elements. The first
sheet of the worksheet contains a zip code and a varying number of

streets.
That number of streets determines how long each query string will be. With
10 streets, the queries are 35, 44, 56 and 107 lines long.

Each query has a title cell as the first line that is just there to label
the query. And there are several empty rows separating each query.
Everything in the query is, including the title, in column A.

I want to make a button that will select and copy the query. I have

recorded
a macro that will work just fine. I just need to know what to do to turn a
cell into a button, since the macro should do the rest.

What event do I need to trap? And what object to I put that event handler
in?

Also, once I figure that out, I need to know how to add that event handler
to the sheet as I build the queries.

My thinking is:

Add the query label
move over three cells and Add the button
move back three cells and down one row and Build the query

Then do the same thing again for the next three queries.

I know I got kind of wordy here, but I hope someone can point me in the
right direction.

Thanks,
Ken Loomis









  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Thanks Nacho & Harald

Betweeen your two replies, I got it to work and learned a lot in the
process.

Thanks,
Ken Loomis

"Ken Loomis" wrote in message
...
I am building a worksheet that builds four database queries that will be
copied and pasted into the DBMS for now. About 80% of each of these queries
never changes, so I use 4 sheets to hold those static elements. The first
sheet of the worksheet contains a zip code and a varying number of streets.
That number of streets determines how long each query string will be. With
10 streets, the queries are 35, 44, 56 and 107 lines long.

Each query has a title cell as the first line that is just there to label
the query. And there are several empty rows separating each query.
Everything in the query is, including the title, in column A.

I want to make a button that will select and copy the query. I have
recorded a macro that will work just fine. I just need to know what to do
to turn a cell into a button, since the macro should do the rest.

What event do I need to trap? And what object to I put that event handler
in?

Also, once I figure that out, I need to know how to add that event handler
to the sheet as I build the queries.

My thinking is:

Add the query label
move over three cells and Add the button
move back three cells and down one row and Build the query

Then do the same thing again for the next three queries.

I know I got kind of wordy here, but I hope someone can point me in the
right direction.

Thanks,
Ken Loomis









  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Make a Cell Act like a Button

you can use buttons from the controls tool box (left click on a tool
bar to bring up a list and tickm it),

Draw the button on the sheet, and then dobble click it,

between the code line wite the name of the macro you want to run

ie.

sub Command1_click
My_Macro
end sub

you can also draw a shap (from the drawing tool bar) on to a sheet and
asign a macro to this, left click and pick the "Assign macro" option
from the short cut menu.
here a tip, if you are doing this then you can protect the sheet, and
you will get a nice looking hand icon over the picture!

good luck
ross


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
make a cell into a button RGlade Excel Discussion (Misc queries) 1 January 28th 08 07:35 PM
use "button" to make calculation ignore a cell Excel Worksheet Functions 5 March 21st 06 04:54 PM
How to make a button conditional Jan V. Excel Programming 2 April 27th 04 11:53 PM
make button - assign to cell tegger Excel Programming 3 November 6th 03 11:39 AM
Make a cell into a Macro button Al[_4_] Excel Programming 5 November 5th 03 10:15 AM


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