VBA Word Userform call again with button if changes in the content

Hi guys,

I'm trying to figure out a way to recall the userform if there is some changes in the textboxes (typo's)

I found out how to call the userform with this code:

Private Sub Menu_Click()


End Sub

Open in new window

but when i make the changes and push ok it does not change the text but add's it to the current text.... is there a way to call it correctly?
Who is Participating?
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.

To be clear about what you are asking.

I suppose that you have a UserForm set up so that when the user presses the 'OK' button, it loads data from the UserForm text boxes on to the document.

You now need a way for the user to open the UserForm again and repeat the process because he has noticed an error in the 'downloaded' text.

You must already have a macro to open the UserForm so select the dropdown arrow at the right of the Quick Access Toolbar (on the left of Word window's title bar). Choose 'More Commands..'  and  then 'Macros' in the top left-hand box of the 'Word Options' window. Find your macro, and move it across to the right-hand list with the 'Add' button. 'OK' the window away and you should have a new QAT button to open the UserForm again
HakumAuthor Commented:
Hi GrahamSkan,

Thank you for your reply,

it is correctly understood that the userform will insert the data, and i want to repeat the process :)

that was the first thing i tried since it should work but i cant seem to get what i'm doing wrong since the code is not there... :S

have a look:

You are looking in the Normal template (the right-hand combo has 'For all documents' selected). You will need to choose your custom template from that list.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

HakumAuthor Commented:
ahhhh right.. SORRRY!!! my bad!! DOH! thank you for being soo patient with me im really trying to learn here, thank you sooo much for all the help!

That said I have no idea what i'm doing wrong for some reason the macro does not show.... i have tried to make a new module and make a call on it but it does not pop up on the list... am i doing something thing wrong? (obvisouly) hehe

i'm abit fustrated now....
The previous advice I gave you refers to which template is to have the button.

The reason that your macro does not appear is that the procedure is 'Private'. Remove that word or replace the word with Public, and you should see the macro in the left-hand list.

This begs the question of 'how do you run the macro in the first place?'
HakumAuthor Commented:
The button is working now, although the text that is already inserted does not get removed... is there a way to clear the content that was inserted at the bookmarks earlier??
If the bookmark is empty (with the start and the end in the same place) and If you set the text to the bookmark's range, the text will be placed after the bookmark. if you do it again, the same thing will happen, so
ActiveDocument.Bookmarks("mybmk").Range.Text = "ABC"
ActiveDocument.Bookmarks("mybmk").Range.Text = "DEF"

Open in new window

will produce "DEFABC" after the bookmark. If the bookmark is not empty, i.e. the length of its range is greater than zero, then the first line will replace the range with the new text. Unfortunately the bookmark is included in the range, so it gets deleted. The second line will then produce a run-time error.

I use a procedure like this if the bookmarks might have to be reused later:
Sub FillBookmark(doc As Document, strText As String, strBookMarkName As String)
    Dim rng As Range
    Set rng = doc.Bookmarks(strBookMarkName).Range
    rng.Text = strText
    're-add the bookmark to ensure that it still exists and that it contains the new text
    doc.Bookmarks.Add strBookMarkName, rng
End Sub

Open in new window

If the bookmarks have been filled as above, you can read the text and pre-load the userform like this
Sub UserForm_Activate()
    TextBox1.Text = ActiveDocument.Bookmarks("bookmark1").Range.Text
End Sub

Open in new window


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
HakumAuthor Commented:
Okay, makes sense! thank you explaining its so well specially for me as a newbie, i'm still learning :)

I havn't writtin it like as you have states and the bookmarks does not get deleted they stay where they should be..  this is how i have coded the bookmarks ref.

Selection.TypeText Text:=Me.txtmomfrad

Open in new window

with the code you have states above, will i need to type in all the bookmarks in the code again or how??

I'm sooo fustrated!!!! arrrrrrggghhh!!!!! almost giving up on VBA!
I'm afraid you will. It's a part of the learning process.
I have been trying to work out a way of doing a find and replace, but it's a bit too complicated for that.
HakumAuthor Commented:
Thank you sooo much for your patience and time! you rock!!!!

i will try to have another look at it in a few days... i'm even speaking VB'ish in my sleeep these days lol!
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
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.