View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
tr00per03 tr00per03 is offline
external usenet poster
 
Posts: 4
Default how to update Listbox of sheetnames if user changes sheetnames?

Thanks for the code suggestions. Those are great ways to initially add
the worksheet names to the listbox, and i use similar code. However,
since i'm using vbModeLess when showing the UserForm, the user has the
ability to interact with the Excel workbook and/or the UserForm as the
user chooses. Unfortunately, this is where the problem arises. By
allowing the user to interact with the Excel workbook, the user can of
course choose to change a worksheet name. I haven't found any sort of
worksheet or workbook event that fires for this particular action
(changing the worksheet name).

I've even tried using a function in a worksheet cell (name:
sheetname_cell) that calculates the worksheet name each time it's
changed. And again, I didn't really find a good use for that becuase,
although the cell value would change to the new worksheet name
correctly, no event would fire as a result of the cell changing its
value. Or at least...even when the calculate event would fire, i had
no way of knowing which cell on the worksheet had actually calculated
(the Worksheet_Calculate event doesn't give a Target parameter.)
Worksheet_Change provides a Target parameter, but in this case, the
Worksheet_Change event doesn't fire, since i have a function in the
cell - ahh.....the ol' Catch-22.

To solve this problem, as is, i think i need one of two things:
a) I need a Worksheet_NameChanged event (of sorts), or a reasonable
work-around
b) I need to be able to target cells after they calculate (like the
Worksheet_Change event does).

I just thought of this too: Is there a way to run a sub/function when
the user returns focus to the UserForm? If so, then maybe each time
focus is returned from the workbook to the UserForm, i could update the
values of listbox then - instead of after each Worksheet_Calculate
event.

One thing that i want to avoid is cross-checking the sheetname_cell
with the actual sheet name each time a Worksheet_Calculate event is
fired - because i do lots and lots of calculations in this particular
project. That would greatly increase the operating time of the code.
Then again, i haven't tested this yet, so maybe that's the next thing
to try. Maybe the time required to cross-check the sheetname_cell with
the actualy sheet name won't even be noticeable to the user between
each calculation.

The other thing i could do - make the UserForm modal - not allow access
to the workbook until the user is done with the UserForm. Then again,
that's not really how i originally intended for this project to work.

Phew...I hope this additional information is helpful. Again, thank you
all for your posts and emails. Fingers-crossed that we can come up
with a good-enough solution.

I'm going to go work on the "update listbox when focus is returned to
the UserForm" idea.

Happy programming.

Troy