Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2011, 11:09 PM
ilkks ilkks is offline ASK and REF field problem Windows Vista ASK and REF field problem Office 2007
Novice
ASK and REF field problem
 
Join Date: May 2011
Posts: 23
ilkks is on a distinguished road
Default ASK and REF field problem

I want to ask the document-template-user to insert his name. And then his name automaticly get copied to different places around the document.



This is working:

I have Text From Field, I double-click it and insert the name to 'Default text', and I write to bookmark field 'testBookmark'. I got { REF testBookmark } all over the document. I select the whole document and update by pressinf F9. And voilą!

This is what I want:


I want more sophisticated approach of inserting the name. For example using ASK-field that is launched by doubleclicking MacroButton. The sub of the MacroButton is:

Code:
Sub Macro3()

' Macro3 Macro
' Launch ASK-field and update the REF-fields

    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "ASK  testBookmark ""Write your name here"" \d First name Last name \o ", PreserveFormatting:=True
    
    Selection.WholeStory
    Selection.Fields.Update
    
End Sub
This is not working properly. It updates REF-fields, which is fine, but. First of all it asks me to write the name 2 times, and after that the MacroButton disappeares. I want to keep MacroButton alive so I can change the name if necessary.
Reply With Quote
  #2  
Old 05-26-2011, 12:06 AM
macropod's Avatar
macropod macropod is offline ASK and REF field problem Windows 7 32bit ASK and REF field problem Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Hi ilkks,

If you check the formfield's 'calculate on exit' property, you don't need a macro to update the cross-references.

Conversely, If you use an ASK field coded as:
{IF{REF BkMk}= {DOCPROPERTY Author} {ASK BkMk "Write your name here" \d {DOCPROPERTY Author}}}
or:
{ASK BkMk "Write your name here" \d {DOCPROPERTY Author}}
and an AutoOpen macro whose code is:
Code:
Sub AutoOpen
ActiveDocument.Fields.Update
End Sub
you don't need the MACROBUTTON field.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-26-2011, 01:13 AM
ilkks ilkks is offline ASK and REF field problem Windows Vista ASK and REF field problem Office 2007
Novice
ASK and REF field problem
 
Join Date: May 2011
Posts: 23
ilkks is on a distinguished road
Default

Thanks Paul for your reply.

Since I am so keen on Macrobuttons I put these {}-fields next to each other




{ Macrobutton AutoOpen Double-click Me }{ASK BkMk "Write your name here" \d {DOCPROPERTY Author}}}

And edited AutoOpen-macro a bit so it updates only {REF BkMK}-fields:

Code:
Sub AutoOpen()

'Updates/launches ASK-field next to Macrobutton
Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.Fields.Update

'Updates only REF-fields with bookmark named BkMk
    Dim Fld As Field
With ActiveDocument
  For Each Fld In .Fields
    With Fld
      If .Type = wdFieldRef Then
        If Split(Trim(.Code.Text), " ")(1) = "BkMk" Then .Update
      End If
    End With
  Next
End With

End Sub
I was wondering could the inserted bookmark become the DisplayText for the MacroButton, similar to thread https://www.msofficeforums.com/vba/7...html#post18034

Then there would be one extra line to the AutoOpen-macro, something like this:

Code:
Selection.Fields(1).Code.Text = "MACROBUTTON AutoOpen " & BkMk
But I don't know the correct format for BkMk-bookmark.

Last edited by ilkks; 05-26-2011 at 03:32 AM.
Reply With Quote
  #4  
Old 05-26-2011, 01:58 AM
macropod's Avatar
macropod macropod is offline ASK and REF field problem Windows 7 32bit ASK and REF field problem Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Hi ilkks,

You could do that by changing the content of a {DOCPROPERTY Author} field (if there is one) to {REF BkMk}. I'll leave you to figure that out - you've got enough code to show you how to edit a field if it exists.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
ASK and REF field problem office 2003 - "to" field problem in new email bruce_hyman Outlook 2 10-25-2010 08:04 PM
How to refer a field in another field DaveSmith Word 0 08-24-2010 06:44 PM
merge field formatting problem with "text to be inserted before" wissam Mail Merge 0 12-13-2009 12:50 AM
Field Help BChianciola Word 0 11-09-2009 01:14 PM
ASK and REF field problem Text Form Field formatting problem Toshii Word 1 06-08-2009 07:21 PM

Other Forums: Access Forums

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