Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2022, 11:51 PM
pfigen@gmail.com pfigen@gmail.com is offline How can I re-populate my userform after closing the document? Windows 10 How can I re-populate my userform after closing the document? Office 2021
Novice
How can I re-populate my userform after closing the document?
 
Join Date: May 2022
Posts: 2
pfigen@gmail.com is on a distinguished road
Default How can I re-populate my userform after closing the document?

Hi, my first post here, so please go easy on me

I have a Word document using two separate userforms to fill in information into bookmarks in the main doc. Everything is working fine, the bookmarks are updated and I can re-open the userforms as long as the main doc is not saved and closed. The challenge is that if I close the main doc, and opens it again, I have to fill in all the textboxes in the userform again. Is there a way to make the userform automatically read the bookmarks upon opening?

Here is what I have done so far:

When the doc is opened I have the following code:

Private Sub Document_Open()
UserForm1.Show
UserForm2.Show


End Sub

I can also open the userforms by two command buttons:

Private Sub ShowUserForm1_Click()
UserForm1.Show
End Sub

Private Sub ShowUserForm2_Click()
UserForm2.Show
End Sub

Then, the UserForm1 uses the following code to insert data to a bookmark:

Private Sub OKbutton_Click()
Dim BMClientCompanyName As Range

Set BMClientCompanyName = ActiveDocument.Bookmarks("NameOfClientHeader").Ran ge
BMClientCompanyName.Text = Me.TextBoxClientCompanyName.Value
ActiveDocument.Bookmarks.Add "NameOfClientHeader", BMClientCompanyName

Me.Repaint
UserForm1.Hide


Any support will be highly appreciated!
Reply With Quote
  #2  
Old 05-04-2022, 08:39 AM
Italophile Italophile is online now How can I re-populate my userform after closing the document? Windows 11 How can I re-populate my userform after closing the document? Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

As your bookmarks enclose the text you insert all you need to do is reverse the logic of your existing code. You would put this code into the Initialize event of the user form, e.g.

Code:
Private Sub UserForm_Initialize()
    Me.TextBoxClientCompanyName.Value = ActiveDocument.Bookmarks("NameOfClientHeader").Range.Text
End Sub
Reply With Quote
  #3  
Old 05-05-2022, 02:08 AM
pfigen@gmail.com pfigen@gmail.com is offline How can I re-populate my userform after closing the document? Windows 10 How can I re-populate my userform after closing the document? Office 2021
Novice
How can I re-populate my userform after closing the document?
 
Join Date: May 2022
Posts: 2
pfigen@gmail.com is on a distinguished road
Default

Thank you so much, Italophile, that solved my problem and saved me and my colleagues a bunch of time
Reply With Quote
Reply

Tags
bookmarks, populate, userform



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I re-populate my userform after closing the document? How to populate a userform combobox from a table in the same document jrooney7 Word VBA 2 04-14-2019 06:30 PM
Dynamic Userform multiselect listbox populate trevorc Excel Programming 1 12-03-2018 02:49 PM
Userform calls other userform, then populate worksheet Lehoi Excel Programming 0 02-03-2016 02:58 PM
Trying to populate Word bookmarks with excel UserForm smd1112 Excel Programming 7 09-03-2014 09:42 PM
Word doc bug when closing from userform command button click macro Joe Patrick Word 1 07-05-2011 08:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft