View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Can the Text on a button form be referenced from a cell?

You would need to show us the code for the macros that are being interfered
with as well as any existing Change event code you might have before we can
tell you how to integrate my code into your project. I'm thinking (off the
top of my head) that you may be able to solve the macro interference problem
by doing something like this. Add a Module to your project (Insert/Module
from VBA editor's menu bar) and put this line of code in it...

Public SkipButtonCode As Boolean

Then change my suggested Change event code to this...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not SkipButtonCode Then
ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = _
"Print " & Range("A1").Value
SkipButtonCode = False
End If
'
' Put any other Change event code you have here
'
End Sub

Finally, put this code line at the beginning of all your macros...

SkipButtonCode = True

Doing all of the above should make the button caption changing code work the
same as it does in a new project.

--
Rick (MVP - Excel)


"Don M." wrote in message
...
Rick, this works if I try it on a new, blank sheet. But, when I try this
in
the existing sheet it interferes with other macros thst I run. I'm not
familiar with using code on the sheet tab. I'll have to read up on how
putting code there is different from the VB Editor that I usually see.
Don

"Rick Rothstein" wrote:

The only reason I wanted to know where you got the button from is its
origin
makes a difference on how you address it in code. Give the following a
try.
Right click the tab at the bottom of the worksheet and select "View Code"
from the popup menu that appears, then copy/paste the following into the
code window that appears...

Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = _
"Print " & Range("A1").Value
End Sub

Now, go back to the worksheet and enter something into A1... the button
caption (for the button named Button 1) should change as you wanted.

--
Rick (MVP - Excel)


"Don M." wrote in message
...
Yes, there are nine cells who's text change according to the data
imported. I
would like one of 9 different buttons to reference one of these nine
cells.

A1 = TWE
B1 = TMW
C1 = TNE
D1 = TMA
E1 = TSE
F1 = TSC
G1 = TGL
H1 = TCE
I1 = TNC

Then the Button 1 says "Print TWE" and runs a macro assigned to it. It
will
always run that macro, regardless of what the text is. The Button 2
then
says
"Print TMW", etc .....

The next time I use the spread sheet the data in those nine cells will
be
different text, and the buttons need to correlate to that text and will
still
run the same macros that are assigned to them.

The only thing that changes is the text on the buttons.

As for where the buttons came from, I used the Forms toolbar and drew
the
button out with the curser. But, I can use a different button if I have
to
to
make this work.

Don

"Rick (MVP - Excel)" wrote:

You mention having "generic buttons"... plural... are you asking for
this
functionality on a single button? That is, is A1 associated with only
one
of
the several buttons you have and, as such, only that button's caption
will
be changed as A1 changes? Also, where did you get the button from...
the
Form's Toolbar or the Control Toolbox's Toolbar?

"Joel" wrote:

the problem is if you have more than one button on a worksheet. Excel
will
not know which button is associated with each cell unless you have a
table
in
excel indicating the button Name and the cell on the worksheet.