Assign a macro to specific text in a textbox

Bill Hamilton

Board Regular
Joined
Mar 30, 2004
Messages
91
Assign a macro to specific text in a textbox created by macro.

I'm generating a display of some information to the user containing data derived by a macro along with explanatory text. I then want the user to be able to Copy that data and paste it into the sheet he's seeing (or anywhere, really) while still viewing the generated display. I can't use either Msgbox or a Form as the focus apparently stays with that and text on those is not copyable anyway (?). Finally, whether or not the user decides to copy any text from what's displayed, he should then be able to dismiss it by clicking on, say, a 'Cancel' button or something.

Instead of those, I thought of using a Text Box, but so far I haven't found any way of getting a macro assigned to any internal text that is not part of anything he might want to copy so that the box can be dismissed once text has been copied.

For example, the display generated might show something like this:

Hi User,
If desired, please copy the text on the next line and paste it whereever you want.
(text to copy)
Dismiss this box by clicking HERE
Have a nice day, Bill

I want a method of allocating a macro to the word HERE so that the whole display can be removed automatically by clicking on it, whether or not the user selects and copies the text. Can a Command Button be inserted into a Text Box? That might do it. I know how to assign a macro to a whole Text Box, but that isn't any use here as the user must be able to select the copyable text.

From research that might not be possible, but I'd be delighted to be set straight.

If a Form can be made to do this I'd be grateful for an explanation. Forms aren't my strongest point unfortunately, but I'm familiar with the basics.

Any advice would be appreciated.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Thanks you, I'll check it out. At first glance it looks a little beyond my current understanding on Forms, but I'll dig into it.

Speaking to someone offline about my problem, he came up with the blindingly obvious suggestion of displaying two text boxes, one bigger one with all my text etc, and another smaller one inside it containing 'Dismiss' or something, with a macro assigned to it which would remove both boxes. The little one could even be formatted to look at least a little like a 'proper' command button. Might give that a try - much easier on this tired old brain.

As for posting this three times, I apologise but I have no idea what happened. I swear I hit the Post button only once. Didn't even do a Preview. What I normally do for posting more than just a few words is to compose it all in Notepad first then paste it all in and Post it after a quick check. Beats me.
 
Upvote 0
Hi Bill,

Not your post, it was my post that came up 3 times. It displayed an error first time so I posted it again and it ended up showing three.
 
Upvote 0
Thanks. Had me worried there!

I think I'll mark this as solved as I have made good progress with Plan B (double textboxes) and I got that working fine without too steep a learning curve.

Case closed.
 
Upvote 0

Forum statistics

Threads
1,203,607
Messages
6,056,284
Members
444,855
Latest member
archadiel

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