Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-2014, 03:05 AM
BoringDavid BoringDavid is offline Is it possible to take an input from a UserForm in one document to a UserForm in a do Windows XP Is it possible to take an input from a UserForm in one document to a UserForm in a do Office 2010 32bit
Novice
Is it possible to take an input from a UserForm in one document to a UserForm in a do
 
Join Date: Sep 2013
Posts: 19
BoringDavid is on a distinguished road
Default Is it possible to take an input from a UserForm in one document to a UserForm in a do

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
The “process document” provides details of what we are going to do and currently does not change; however, it does include several telephone numbers. I have now been asked to update the document so that the telephone numbers are amended dependent on where the letter is being sent

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?
Reply With Quote
  #2  
Old 05-09-2014, 03:52 AM
macropod's Avatar
macropod macropod is offline Is it possible to take an input from a UserForm in one document to a UserForm in a do Windows 7 32bit Is it possible to take an input from a UserForm in one document to a UserForm in a do Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 05-09-2014, 04:11 AM
BoringDavid BoringDavid is offline Is it possible to take an input from a UserForm in one document to a UserForm in a do Windows XP Is it possible to take an input from a UserForm in one document to a UserForm in a do Office 2010 32bit
Novice
Is it possible to take an input from a UserForm in one document to a UserForm in a do
 
Join Date: Sep 2013
Posts: 19
BoringDavid is on a distinguished road
Default

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!
Attached Files
File Type: doc Cleaned VBA Document.doc (60.5 KB, 10 views)
File Type: doc Process Document.doc (38.5 KB, 11 views)
Reply With Quote
  #4  
Old 05-09-2014, 04:51 AM
macropod's Avatar
macropod macropod is offline Is it possible to take an input from a UserForm in one document to a UserForm in a do Windows 7 32bit Is it possible to take an input from a UserForm in one document to a UserForm in a do Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
which you would call with code like:
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
Where "IDC is the bookmark name in your “process document”, (IDC = International Dial Code).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-09-2014, 06:33 AM
BoringDavid BoringDavid is offline Is it possible to take an input from a UserForm in one document to a UserForm in a do Windows XP Is it possible to take an input from a UserForm in one document to a UserForm in a do Office 2010 32bit
Novice
Is it possible to take an input from a UserForm in one document to a UserForm in a do
 
Join Date: Sep 2013
Posts: 19
BoringDavid is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 05-09-2014, 09:08 AM
macropod's Avatar
macropod macropod is offline Is it possible to take an input from a UserForm in one document to a UserForm in a do Windows 7 32bit Is it possible to take an input from a UserForm in one document to a UserForm in a do Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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"
where 'LoadUserForm' is the macro name in the 'process document' template.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to take an input from a UserForm in one document to a UserForm in a do Checkbox in Userform 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
Is it possible to take an input from a UserForm in one document to a UserForm in a do Show userform without losing document focus? Or other method to get a graphic to pop? AlexR Word VBA 7 03-31-2013 12:17 PM
Is it possible to take an input from a UserForm in one document to a UserForm in a do How to link userform to another word document SaneMan Word VBA 5 10-14-2011 05:12 AM
Is it possible to take an input from a UserForm in one document to a UserForm in a do Setting focus to specific word document from UserForm SaneMan Word VBA 5 04-01-2011 03:11 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:37 PM.


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