Changing Caption on Button in Spreadsheet out of focus

farhad_mofidi

New Member
Joined
Oct 12, 2006
Messages
7
Hi,

I have two spreadsheets that have exactly the same sheet names and I have the following problem when thay are open at the same time. The sheet that is out of focus pops an alert message to the user and asks him/her if he wants to run a macro. On yes the macro on that sheet starts and one of the things the macro does is select one the Buttons on the sheet (a Form Button, not a comand button) and tries to change the text on that button. This is the code;

ThisWorkbook.Worksheets(sheetName).Shapes(buttonName).Select
Selection.Characters.Text = buttonText & vbLf & Now()

The button on the sheet out of focus is selected fine but the problem is the second line selects a cell in the sheet that is in focus.
How do I change the text on the button that is on the out of focus spreadsheet?
 
I did, but I didn't have the reference setup to the object in the first post.

selection.TextFrame.Characters.Text = buttontext & vbLf & Now()

Which may have replaced the first problem with a second. The second post I removed the textframe bit, cause of your post after my first one.

Code:
The code works fine when the spreadsheet is in focus, the problem is when its out of focus

Which made me think I was maybe missing something.

Anyway, glad you got it working, which is the main thing.

Cal
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top