ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to sort buttons (https://www.excelbanter.com/excel-programming/408422-how-sort-buttons.html)

Ray C

How to sort buttons
 
I have a VBA loop that reads file names from a directory. In the end I have a
worksheet with a bunch of filename listed (plus other file info). I also add
a button on each line that allows me to open the file. It all works
fine...until the user plays around with the sorting...When columns are
sorted, everything gets sorted except the buttons. In other words, after the
user sorts, the buttons on each line open the wrong files.

Here's the code that adds the button on each line:

sht.Range("AA" & intCurrentLine).Select
With mySheet.Buttons.Add(ActiveCell.Left, ActiveCell.Top, ActiveCell.Width,
ActiveCell.Height)
.Name = ...
.OnAction = ...
.Characters.Text = ...
End With

This code is inside another bigger loop that reads each file.

Thanks in advance
Ray


Tom Hutchins

How to sort buttons
 
Just a thought ... If you create hyperlinks instead of buttons on each row,
you will still get one-click functionality to open the files, and the cells
with the hyperlinks will sort normally.

Hope this helps,

Hutch

"Ray C" wrote:

I have a VBA loop that reads file names from a directory. In the end I have a
worksheet with a bunch of filename listed (plus other file info). I also add
a button on each line that allows me to open the file. It all works
fine...until the user plays around with the sorting...When columns are
sorted, everything gets sorted except the buttons. In other words, after the
user sorts, the buttons on each line open the wrong files.

Here's the code that adds the button on each line:

sht.Range("AA" & intCurrentLine).Select
With mySheet.Buttons.Add(ActiveCell.Left, ActiveCell.Top, ActiveCell.Width,
ActiveCell.Height)
.Name = ...
.OnAction = ...
.Characters.Text = ...
End With

This code is inside another bigger loop that reads each file.

Thanks in advance
Ray


Jean-Yves TFELT

How to sort buttons
 
Hi Ray,

I use another scirpt that list all file in the search directory and adds a
hyperlink to open.
If interested, please post back.

Regards
JY

"Ray C" wrote in message
...
I have a VBA loop that reads file names from a directory. In the end I have
a
worksheet with a bunch of filename listed (plus other file info). I also
add
a button on each line that allows me to open the file. It all works
fine...until the user plays around with the sorting...When columns are
sorted, everything gets sorted except the buttons. In other words, after
the
user sorts, the buttons on each line open the wrong files.

Here's the code that adds the button on each line:

sht.Range("AA" & intCurrentLine).Select
With mySheet.Buttons.Add(ActiveCell.Left, ActiveCell.Top,
ActiveCell.Width,
ActiveCell.Height)
.Name = ...
.OnAction = ...
.Characters.Text = ...
End With

This code is inside another bigger loop that reads each file.

Thanks in advance
Ray





Ray C

How to sort buttons
 
Hi Tom,

I solved my problem with the buttons, but I like your idea better. Oh well.

Thanks anyways
Ray


"Tom Hutchins" wrote:

Just a thought ... If you create hyperlinks instead of buttons on each row,
you will still get one-click functionality to open the files, and the cells
with the hyperlinks will sort normally.

Hope this helps,

Hutch

"Ray C" wrote:

I have a VBA loop that reads file names from a directory. In the end I have a
worksheet with a bunch of filename listed (plus other file info). I also add
a button on each line that allows me to open the file. It all works
fine...until the user plays around with the sorting...When columns are
sorted, everything gets sorted except the buttons. In other words, after the
user sorts, the buttons on each line open the wrong files.

Here's the code that adds the button on each line:

sht.Range("AA" & intCurrentLine).Select
With mySheet.Buttons.Add(ActiveCell.Left, ActiveCell.Top, ActiveCell.Width,
ActiveCell.Height)
.Name = ...
.OnAction = ...
.Characters.Text = ...
End With

This code is inside another bigger loop that reads each file.

Thanks in advance
Ray



All times are GMT +1. The time now is 06:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com