![]() |
|
![]() |
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
![]()
All our letter templates open with a UserForm that the user populates; one of the inputs dictates if the letter is going overseas, which adjusts information within the template such as our telephone number (it adds +44 to the beginning of the number). One particular template then adds a “process document” using this code:
Code:
Documents.Add Template:="File Path\process document.dot", NewTemplate:=False When this opens a UserForm appears and the user chooses one of two CommandButtons which will then amend the telephone numbers. My question is, is it possible for the first document to launch the “process document” and then either select the appropriate CommandButton or to negate this stage altogether and update the “process document” without a UserForm? |
#2
|
||||
|
||||
![]()
It's certainly possible, but it would be much easier to provide specific advice if you could attach a document to a post with some representative data (delete anything sensitive). You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Here is the 'cleaned' documents, I have removed a large amount of data from the document. However, the relevant parts should all be there.
Essentially, if ComboBox 1 = "UK" then I want VBA to open the "process document" and select "CmdUK" from UserForm "Process" and if ComboBox 1 <> "UK" then I want VBA to open the "process document" and select "CmdNUK" from UserForm "Process". Many thanks for your help! |
#4
|
||||
|
||||
![]()
All you need do, then, is add bookmark to the “process document” in front of one telephone number, and cross-references to that bookmark in front of the rest of the telephone numbers, then update the bookmark with the country code, followed by .Fields.Update. However, there is an issue with the way your code currently 'updates' bookmarks. Instead of updating them, it merely inserts text after them. To update a bookmark you should use code like:
Code:
Sub UpdateBookmark(StrBkMk As String, StrTxt As String) Dim BkMkRng As Range With ActiveDocument If .Bookmarks.Exists(StrBkMk) Then Set BkMkRng = .Bookmarks(StrBkMk).Range BkMkRng.Text = StrTxt .Bookmarks.Add StrBkMk, BkMkRng End If End With Set BkMkRng = Nothing End Sub Call UpdateBookmark("Address1", vbCrLf & ComboBox1) Similarly, for adding & updating your “process document”, you might use code like: Code:
Documents.Add Template:="File Path\Process Document.dot", NewTemplate:=False If ComboBox1 <> "UK" Then Call UpdateBookmark("IDC", "+44 ") ActiveDocument.Fields.Update End If
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Thanks for your update Paul. However, the bookmark updating is not the issue here. I need the first document to add the "process document" then select the appropriate command button.
|
#6
|
||||
|
||||
![]()
To do what you want would probably require you to:
1. create a document variable or custom document property in the template 2. when you create a new document from the template, update the new document's copy of the document variable or custom document property 3. have the code in your userform read the document variable or custom document property in the activedocument and check the appropriate button programmatically. I'm not sure whether the AutoNew macro you now have would fire before the document variable or custom document property is updated. If it does, you wouldn't be able to use the AutoNew macro; instead you'd need to update the document variable or custom document property then call another macro to load the userform via Application.Run. For example, in your 'Cleaned VBA Document' document: Code:
'Code to populate the document variable or custom document property, then Application.Run ActiveDocument.AttachedTemplate.FullName & "!Module1.LoadUserForm"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
lukael | Excel Programming | 5 | 02-18-2014 05:20 AM |
Userform Code not quite right - help please | vbanovice | Word VBA | 1 | 09-29-2013 09:20 PM |
![]() |
AlexR | Word VBA | 7 | 03-31-2013 12:17 PM |
![]() |
SaneMan | Word VBA | 5 | 10-14-2011 05:12 AM |
![]() |
SaneMan | Word VBA | 5 | 04-01-2011 03:11 PM |