Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Passing info to macro from icons

Hi All

To preface my question:

* I like to dumb things down for my users my adding icons (a gif image
thru Insert-Picture-From File) that perform tasks such as sorting.
This just reduces their role to clicking icons instead of controlling
the sort at a lower level through the menu system.

* I have an icon at the top of each column of data. The icon says
"Sort" and I intend for my users to click this button when they want
that column sorted.

* I have my macro subroutine (MySort) written generically taking as a
parameter the column to sort on so in my code I can just call
My_Sort("C") or MySort(ActiveCell.Column).

* At the moment I have to have wrapper subroutines for each icon on my
sheet - so if I have icons on columns A,B & C I need : My_Sort_A,
My_Sort_B and My_Sort_C which just call My_Sort with the correct
column. It is these wrapper subroutines which I then attach to the
correct icons with a right click and "Add/Attach Macro".

Obviously this wrapper solution is fine for a small amount of columns
but it does not scale AND it is not elegant :(

I could get around this if I could pass info about the location of the
clicked icon to my code but as far as I can see you can only tell Excel
to run a macro when an icon is clicked and not any information about
where the icon is located - the active cell before the icon is clicked
is still the active cell when the icon is clicked.

Is there anyway to get into my code the location (cell, column or row)
of the icon/drawing that was clicked by the user?

Thanks for any help in advance - I have used this newsgroup a *lot* to
get things done but this is my first post.

Chris

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Passing info to macro from icons

why bother with all that overhead. Just copy paste this to the sheet module
(right click sheet tabview code). Use a defined name for sortrange. Now
just inform them that the range will be sorted by whatever column they
double click.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel
As Boolean)
[sortrange].Sort Key1:=Cells(1, activecell.column), _
Order1:=xlAscending, Orientation:=xlTopToBottom
End Sub

--
Don Guillett
SalesAid Software

"Chrisso" wrote in message
oups.com...
Hi All

To preface my question:

* I like to dumb things down for my users my adding icons (a gif image
thru Insert-Picture-From File) that perform tasks such as sorting.
This just reduces their role to clicking icons instead of controlling
the sort at a lower level through the menu system.

* I have an icon at the top of each column of data. The icon says
"Sort" and I intend for my users to click this button when they want
that column sorted.

* I have my macro subroutine (MySort) written generically taking as a
parameter the column to sort on so in my code I can just call
My_Sort("C") or MySort(ActiveCell.Column).

* At the moment I have to have wrapper subroutines for each icon on my
sheet - so if I have icons on columns A,B & C I need : My_Sort_A,
My_Sort_B and My_Sort_C which just call My_Sort with the correct
column. It is these wrapper subroutines which I then attach to the
correct icons with a right click and "Add/Attach Macro".

Obviously this wrapper solution is fine for a small amount of columns
but it does not scale AND it is not elegant :(

I could get around this if I could pass info about the location of the
clicked icon to my code but as far as I can see you can only tell Excel
to run a macro when an icon is clicked and not any information about
where the icon is located - the active cell before the icon is clicked
is still the active cell when the icon is clicked.

Is there anyway to get into my code the location (cell, column or row)
of the icon/drawing that was clicked by the user?

Thanks for any help in advance - I have used this newsgroup a *lot* to
get things done but this is my first post.

Chris



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Passing info to macro from icons

Public Sub Pic_Click()
Dim sname as String
Dim pic as Picture
Dim rng as Range
sname = Application.Caller
set pic = Activesheet.Pictures(sName)
set rng = pic.TopLeftCell
'msgbox "row: " & rng.row & " column: " & rng.column
rng.CurrentRegion.Sort Key1:=rng, _
Order1:=xlAscending, _
Orientation:=xlTopToBottom

End Sub

should get you started. Place this code in a general module (not the sheet
module). Assign this same single macro (or one adjusted to your needs) to
all the icons.

--
Regards,
Tom Ogilvy



"Chrisso" wrote in message
oups.com...
Hi All

To preface my question:

* I like to dumb things down for my users my adding icons (a gif image
thru Insert-Picture-From File) that perform tasks such as sorting.
This just reduces their role to clicking icons instead of controlling
the sort at a lower level through the menu system.

* I have an icon at the top of each column of data. The icon says
"Sort" and I intend for my users to click this button when they want
that column sorted.

* I have my macro subroutine (MySort) written generically taking as a
parameter the column to sort on so in my code I can just call
My_Sort("C") or MySort(ActiveCell.Column).

* At the moment I have to have wrapper subroutines for each icon on my
sheet - so if I have icons on columns A,B & C I need : My_Sort_A,
My_Sort_B and My_Sort_C which just call My_Sort with the correct
column. It is these wrapper subroutines which I then attach to the
correct icons with a right click and "Add/Attach Macro".

Obviously this wrapper solution is fine for a small amount of columns
but it does not scale AND it is not elegant :(

I could get around this if I could pass info about the location of the
clicked icon to my code but as far as I can see you can only tell Excel
to run a macro when an icon is clicked and not any information about
where the icon is located - the active cell before the icon is clicked
is still the active cell when the icon is clicked.

Is there anyway to get into my code the location (cell, column or row)
of the icon/drawing that was clicked by the user?

Thanks for any help in advance - I have used this newsgroup a *lot* to
get things done but this is my first post.

Chris



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Passing info to macro from icons

Huge thanks to both Don and Tom.

Both solutions do exactly what I wanted and are wonderfully concise.

I have tried them both out with great results. Thankyou very much for
your reply and code.

Cheers
Chris

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
Passing Excel Info To Visio Rob Excel Discussion (Misc queries) 0 January 10th 07 08:25 PM
need help w/ macro prompting with info and pasting the info based on user input drgka55 Excel Programming 8 August 28th 06 06:05 PM
Passing Info Between Macros Rob Excel Programming 2 August 26th 06 01:48 AM
Passing info from macro to UserForm ybazizi Excel Programming 4 April 12th 06 03:09 AM
Saving custom icons associated with a macro John@NGC Excel Programming 2 February 1st 06 08:53 PM


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