![]() |
|
#1
|
|||
|
|||
![]()
Hi Guys,
I'm new here and although I am pretty experienced with VBA for Excel and Access I'm a noob when it comes to Word! I have a userform that auto-populates a template with content e.g name and address, date, subject, letter body, signature etc. The user form has multiple tabs for gathering all the required information prior to inserting it in the document. No problem with that. However, we have different branches and departments each of which has their own letterhead with custom header and footer, which I have as separate templates. What I need to be able to do is to load one of the templates for VBA to populate, based on the selections (from combo's) that the user has made in the userform. The specific issue for me is, how do you open another document and make it editable to VBA, while keeping the userform active? I would be most grateful for any help on this. Thanks Alan |
#2
|
||||
|
||||
![]()
Your process is a bit vague but presumably you will get the office (here a string strOffice) from the userform, so something along the lines of:
Code:
Dim oDoc As Document Dim strOffice As String Select Case strOffice Case "London" Set oDoc = Documents.Add("c:\path\London templatename.dotm") Case "New York" Set oDoc = Documents.Add("c:\path\NY templatename.dotm") 'etc End Select 'do stuff with oDoc
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Hi Graham,
Thank you for this; it will do what I want. Yes I'm getting the office as a string. It was the document.add method that I wasn't aware of. I've just a done test where I added a new document and then programmatically added text to it. The VBA userform is no longer visible as the new document has focus, but since the process is effectively complete once the new document has been created, I can live with that. Many thanks again, Alan |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Open Userform once and apply the same selection to multiple documents | Formd | Word VBA | 2 | 12-12-2017 10:11 AM |
Problem with add-ins that don't work that I can't delete b/c Excel, Word, etc won't open | bcs | Office | 3 | 02-25-2016 03:37 PM |
Powerpoint Userform sharing across all open presentations | James Kreiner | PowerPoint | 2 | 09-24-2014 09:52 AM |
![]() |
Kirsti | Word VBA | 11 | 08-23-2012 07:05 PM |
![]() |
Ole Sarge | Word | 1 | 05-27-2011 03:06 PM |