#1
|
|||
|
|||
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? |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
Quote:
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? |
#4
|
|||
|
|||
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 |
#5
|
||||
|
||||
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 |
#6
|
|||
|
|||
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 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. |
#7
|
|||
|
|||
Quote:
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 |
#8
|
||||
|
||||
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 |
#9
|
|||
|
|||
Quote:
Thanks much! I'll try to contact as well. |
#10
|
|||
|
|||
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. |
#11
|
||||
|
||||
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 |
#12
|
|||
|
|||
Quote:
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. |
#13
|
|||
|
|||
Quote:
Where are you saving it? Where are you putting the code? |
#14
|
|||
|
|||
Quote:
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. |
#15
|
|||
|
|||
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 |
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 |
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 |