Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-14-2020, 07:32 AM
lordbodom lordbodom is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Novice
Fill multiple word docs with 1 vb userform?
 
Join Date: Jul 2020
Posts: 10
lordbodom is on a distinguished road
Default Fill multiple word docs with 1 vb userform?

I have about 6-8 document templates that require almost identical information to be populated into them. I am wondering if there is a way to fill out a VB userform or something similar to have it populate in all the different forms?


I know how to have it fill the info in one form using bookmarks, but not sure if this can be done across multiple documents? Would this be possible?
Reply With Quote
  #2  
Old 08-14-2020, 12:35 PM
Charles Kenyon Charles Kenyon is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

First, I hope you are populating new documents based on the templates, not simply the templates. The word "template" in Word jargon carries a lot of baggage.
Templates in Microsoft Word


Yes, but the UserForm needs full paths to the templates, bookmarks in the templates, etc. You can simplify things by using the same bookmarks in the templates.

You are probably going to want to base your paths on the path for thisdocument. That would make your work more portable.
Reply With Quote
  #3  
Old 08-14-2020, 05:47 PM
lordbodom lordbodom is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Novice
Fill multiple word docs with 1 vb userform?
 
Join Date: Jul 2020
Posts: 10
lordbodom is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
First, I hope you are populating new documents based on the templates, not simply the templates. The word "template" in Word jargon carries a lot of baggage.
Templates in Microsoft Word


Yes, but the UserForm needs full paths to the templates, bookmarks in the templates, etc. You can simplify things by using the same bookmarks in the templates.

You are probably going to want to base your paths on the path for thisdocument. That would make your work more portable.

Thanks for this. Maybe I am reading these wrong, but i think the methods shown has a macro built into every word doc to populate them? I was looking for a solution to populate them all without having to open each word doc up.



Im new to VB to maybe I misread/misunderstood?
Reply With Quote
  #4  
Old 08-14-2020, 07:46 PM
Charles Kenyon Charles Kenyon is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

The examples populate their own document but there is nothing that prevents the userform from creating new documents based on other templates and populating those as well. Again, you are going to have to tell the userform where to find those templates, and what their names are.

Documents.Add method
Documents.Add method (Word) | Microsoft Docs

oDocument2 = Documents.Add
Reply With Quote
  #5  
Old 08-14-2020, 07:55 PM
gmayor's Avatar
gmayor gmayor is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You may find DocBundler (Create multiple documents from commond data sheet) useful.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #6  
Old 08-14-2020, 08:10 PM
Charles Kenyon Charles Kenyon is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

If the templates were in the Project1 folder of the Workgroup Templates folder I would use that as a base path.


I use a function to get that path:


Code:
Private Function WorkGroupPath() As String
'   Written by Charles Kenyon
'   February 28, 2003
'
'   Used by templates menus to set location of templates.
'   Returns workgroup tempates path with "\" at the end.
'
'   This is needed because if the folder is a network drive rather
'   than a folder, it will have the "\" already. If it is a folder,
'   it will not have the backslash. This function gives a string
'   with the backslash in either case.
'
    WorkGroupPath = Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)
    If Right(WorkGroupPath, 1) <> "\" Then
        WorkGroupPath = WorkGroupPath & "\"
    End If
End Function
In my userform, to create a new document from the template Template2.dotx in the Workgroup Templates subfolder Project1 I would use the following statements:


Code:
Dim oDocument2 as Document
Dim strTemplate2 as String


Let strTemplate2 = WorkGroupPath & Project1 & "\Template2.dotx"

Set oDocument2 = Documents.Add(Template:=strTemplate2)

You could then fill in bookmarks in oDocument2 and save it.


Note, I have not tried this code directly but run something similar on a regular basis.
Reply With Quote
  #7  
Old 08-14-2020, 08:43 PM
lordbodom lordbodom is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Novice
Fill multiple word docs with 1 vb userform?
 
Join Date: Jul 2020
Posts: 10
lordbodom is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post

Thanks. This might be the way to go since im very limited in VB and very new. I will play around with it to see if I can get it to do what I need.


update: Im getting an error while trying to populate the docs with docbundler:


Runtime error '5981'
Could not open macro storage


I have the folder created in the sub directory and have enabled all macros. Any suggestions?


Thanks
Reply With Quote
  #8  
Old 08-14-2020, 09:57 PM
gmayor's Avatar
gmayor gmayor is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Quote:
Originally Posted by lordbodom View Post
Runtime error '5981'
Could not open macro storage
I have the folder created in the sub directory and have enabled all macros. Any suggestions?
Thanks
I suggest contacting Greg via his web site. I will contact him and alert him to this thread.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #9  
Old 08-14-2020, 10:03 PM
lordbodom lordbodom is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Novice
Fill multiple word docs with 1 vb userform?
 
Join Date: Jul 2020
Posts: 10
lordbodom is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
I suggest contacting Greg via his web site. I will contact him and alert him to this thread.

Thanks much! I'll try to contact as well.
Reply With Quote
  #10  
Old 08-15-2020, 01:10 AM
lordbodom lordbodom is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Novice
Fill multiple word docs with 1 vb userform?
 
Join Date: Jul 2020
Posts: 10
lordbodom is on a distinguished road
Default

Quote:
Originally Posted by lordbodom View Post
Thanks much! I'll try to contact as well.

Update: Worked after I disabled protect view


Now I cant figure out how to save the new template I created. I edited the form with my custom fields. When I save it as a template and run it, it doesnt run the vba portion.
Reply With Quote
  #11  
Old 08-15-2020, 02:28 AM
gmayor's Avatar
gmayor gmayor is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Did you put the code in the template (and save it as macro enabled) or in your normal template?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #12  
Old 08-15-2020, 07:31 AM
lordbodom lordbodom is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Novice
Fill multiple word docs with 1 vb userform?
 
Join Date: Jul 2020
Posts: 10
lordbodom is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Did you put the code in the template (and save it as macro enabled) or in your normal template?

So i just took the form template that came with docbundler and just renamed the fields and linked them to different bookmarks. I can run it and it populates no problem when i make the changes but dont save. When i save it though, it seems to lose the ability to run. Iv tried saving it in the 03 template file (.dot) as well as macro enabled (.dotm) and it wont run.
Reply With Quote
  #13  
Old 08-15-2020, 01:33 PM
Charles Kenyon Charles Kenyon is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by lordbodom View Post
So i just took the form template that came with docbundler and just renamed the fields and linked them to different bookmarks. I can run it and it populates no problem when i make the changes but dont save. When i save it though, it seems to lose the ability to run. Iv tried saving it in the 03 template file (.dot) as well as macro enabled (.dotm) and it wont run.
If you are using Word 2019 you should be saving as a .dotm file.

Where are you saving it?

Where are you putting the code?
Reply With Quote
  #14  
Old 08-15-2020, 05:47 PM
lordbodom lordbodom is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Novice
Fill multiple word docs with 1 vb userform?
 
Join Date: Jul 2020
Posts: 10
lordbodom is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
If you are using Word 2019 you should be saving as a .dotm file.

Where are you saving it?

Where are you putting the code?

Maybe Im doing it wrong. Here are the steps im doing:


- open the data sheet file template
- remove the restriction to be able to edit
- change the text for the fields
- change the properties of the form fill box and change the bookmark names to the ones per my templates
- re-apply the restrictions to fill form only
- save file

Btw, Im using the word 2003 version of the docbundler template. Trying the 2010 one gives me an error. Iv saved to both the 2003 .dot and the macro enabled .dotm and after saving all the vba code gets stripped out.

My thought was since I was using the same file and not changing any of the code, that it would still be there while saving? Maybe im wrong?


Update: I got it working by saving as just a regular macro enabled word doc and not the template. Seems to be working now. Thank you all for your help with this. Really appreciate it!

Last edited by lordbodom; 08-15-2020 at 08:40 PM.
Reply With Quote
  #15  
Old 08-19-2020, 12:19 PM
Charles Kenyon Charles Kenyon is offline Fill multiple word docs with 1 vb userform? Windows 10 Fill multiple word docs with 1 vb userform? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Cross-posted at: Populate multiple templates using 1 userform
For cross-posting etiquette, please read: A Message to Forum Cross-Posters Excelguru Help Site - A message to forum cross posters
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a UserForm to fill blanks in a letter blanchetdb Word VBA 2 04-05-2019 07:06 AM
Fill userform, combobox and frame based on data from multiple worksheets Divinedar Excel Programming 8 04-26-2018 05:07 PM
Fill multiple word docs with 1 vb userform? Customizing form fill docs with dropdowns strodden Word VBA 13 09-22-2017 06:35 AM
Fill MS-Word docs/forms with name address data from external source yajnaval Word 2 02-14-2015 10:48 PM
Add watermark to multiple word docs mykeee Word 1 09-21-2013 04:01 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:32 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