Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-25-2018, 04:43 AM
AlanC AlanC is offline Word VBA: Open and work with a different doc from userform? Windows 10 Word VBA: Open and work with a different doc from userform? Office 2016
Novice
Word VBA: Open and work with a different doc from userform?
 
Join Date: Jun 2018
Posts: 4
AlanC is on a distinguished road
Default Word VBA: Open and work with a different doc from userform?

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
Reply With Quote
  #2  
Old 06-25-2018, 05:23 AM
gmayor's Avatar
gmayor gmayor is offline Word VBA: Open and work with a different doc from userform? Windows 10 Word VBA: Open and work with a different doc from 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

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
Reply With Quote
  #3  
Old 06-25-2018, 06:58 AM
AlanC AlanC is offline Word VBA: Open and work with a different doc from userform? Windows 10 Word VBA: Open and work with a different doc from userform? Office 2016
Novice
Word VBA: Open and work with a different doc from userform?
 
Join Date: Jun 2018
Posts: 4
AlanC is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
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
Word VBA: Open and work with a different doc from userform? Workaround to have UserForm open from Web Link Kirsti Word VBA 11 08-23-2012 07:05 PM
Word VBA: Open and work with a different doc from userform? Text created in Work 2010- will not open in Word 2007 Ole Sarge Word 1 05-27-2011 03:06 PM

Other Forums: Access Forums

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