Change vba code from inside loaded userform.

Is there a way to modify my excel vba code from inside the loaded user form? For instance, I have two userforms, one with buttons that copies and pastes text. I want to use the second userform to change what the text is that gets copied and what the buttons shown text is.

The code I use for the copy/paste function is:
Dim obj As New DataObject
Dim txt As String

'Put some text inside a string variable
'PURPOSE: Copy a given text to the clipboard (using DataObject)
  txt = "Random Text"

'Make object's text equal above string variable
  obj.SetText txt

'Place DataObject's text into the Clipboard
  obj.PutInClipboard
  

Open in new window



Just to preemptively make everyone aware, no I cannot upload a copy of my workbook.
david franciscoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
It is possible to change the actual VBA code, but that shouldn't be necessary if you just want to change some text/data.
david franciscoAuthor Commented:
In my situation it is necessary. I would like to be able to update the buttons and the text without going to developer mode every time I want to change the text slightly.
Bill PrewIT / Software Engineering ConsultantCommented:
If it were me, and based on some limited information provided here, I wouldn't try and change the VBA code.  I would place the text that will vary into either global variables, or perhaps better still into a special table.  Let the form that presents these get the current values from there, and let the form that needs to change them update those values.  Feels like a cleaner approach.


»bp
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

david franciscoAuthor Commented:
Those are possible solutions, but again, not the ones I am going for. To clarify, I am trying to make this form usable for multiple users (they will have their own copy of the file) and the second userform is to make the process of changing the buttons copy/paste functions
 simpler. I do not necessarily want a cleaner solution.
david franciscoAuthor Commented:
I apologize, I'm not trying to be difficult, I just have no frame of reference on where to start with this code, so I cannot even begin. In addition, the great Google machine has found all of my versions of this question to be to vague.
Bill PrewIT / Software Engineering ConsultantCommented:
This isn't a "drop in" comment at all, but in case these help give you the idea, here are a couple of past questions I participated in that involved VBA code to modify VBA code. Might give you some ideas...



»bp
NorieAnalyst Assistant Commented:
As far as I know you can't change code at runtime, e.g. when a form is loaded.

Will both forms be loaded or will the one you want to alter be closed?
david franciscoAuthor Commented:
When making the change, both will be loaded.
NorieAnalyst Assistant Commented:
Like I said I'm not sure it's possible to change the code, or design, of a loaded form.

I've tried it in the past without much luck, don't have access to any examples at the moment but I'll see if I can find anything later.
Fabrice LambertConsultingCommented:
It looks like your issue is a parameters issues (AKA values tied to users).
what about hiding some parameters in an hidden (and protected) worksheet, and read them ?

Other solution I can see is to take advantage of inheritance, but your description isn't precise enough to provide solution.
GrahamSkanRetiredCommented:
If you give us a better idea of what you need to do, we can give you better advice. All we know is that it concerns a DataObject and two userforms. Whatever it is,  it is highly unlikely that you will need to modify the code itself.
david franciscoAuthor Commented:
You may be correct, I may just have to have the data that gets copied save to a worksheet and pull from there since that can be modified in real time.
GrahamSkanRetiredCommented:
Do you want to copy something, modify it and then paste it somewhere else?
david franciscoAuthor Commented:
So the buttons in user form one have set text that copies to my clipboard. Some buttons are unassigned, and I want to be able to assign the text in userform 2.
david franciscoAuthor Commented:
Or reassign the buttons that already have assignments.
NorieAnalyst Assistant Commented:
What sort of text to the buttons have 'assigned' to them?

How is the text 'assigned'? Is it just the button caption or is there something in the code behind the buttons?
david franciscoAuthor Commented:
Private Sub CommandButton41_Click()
'PURPOSE: Copy a given text to the clipboard (using DataObject)

Dim obj As New DataObject
Dim txt As String

'Put some text inside a string variable
  txt = "***RANDOM TEXT 1"

'Make object's text equal above string variable
  obj.SetText txt

'Place DataObject's text into the Clipboard
  obj.PutInClipboard
  
End Sub

Open in new window

NorieAnalyst Assistant Commented:
How about something like this?

You create a file with basically 2 columns, one for button name and one for the text associated with the button.

When the form opens the data from that file is read into an array/dictionary and when the user clicks a button the appropriate text is pulled and sent to the clipboard.

Would that be at least a start?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
david franciscoAuthor Commented:
It would be a universal fix, and I think that is what I will have to do if I want this to be easily edited by someone with no VBA experience.
david franciscoAuthor Commented:
Thanks so much for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.