Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Excel-style Toolbar Textbox for editing fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
alainr - 09 Jun 2005 20:59 GMT
My problem is that I find myself performing following (too) many times MS Word:

"Right-click on a field in a document" > Click [Edit Field...] > Click
[Field Code] > Set focus in Field Code edit textbox.  ~ 4 mouse clicks, many
motions

I would like word to behave as follows:

When I set the cursor on a field in an MS Word document, I would like to
have a Toolbar component textbox that shows me the contents of the field so
that I can click immediately in the textbox and edit the field on the fly
(like when you click in a Cell in Excel and edit the contents using the
formula bar). Can anyone assess if this is possible and give me a few
pointers where to start to go about implementing this function in Either VBA,
VB or VC++?
Word Heretic - 11 Jun 2005 16:07 GMT
G'day alainr <alainr@discussions.microsoft.com>,

Aye - it may be nice, but let us not forget there are thousands of
users who use Word that have a different modus operandi.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice

alainr reckoned:

>My problem is that I find myself performing following (too) many times MS Word:
>
[quoted text clipped - 11 lines]
>pointers where to start to go about implementing this function in Either VBA,
>VB or VC++?
Cindy M  -WordMVP- - 11 Jun 2005 16:44 GMT
Hi =?Utf-8?B?YWxhaW5y?=,

Why not simply press Alt+F9 (or, to toggle just the selected fields, Shift+F9) to
display the field codes?

> My problem is that I find myself performing following (too) many times MS Word:
>  
[quoted text clipped - 9 lines]
> (like when you click in a Cell in Excel and edit the contents using the
> formula bar).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
alainr - 13 Jun 2005 04:00 GMT
Well, in case anyone is interested in this feature, I managed to implement
something that does the job.  The problem with pressing Shft+F9 or Alt+F9 to
edit the fields is that is screws-up the page layout.  Anyhow, I solved my
problem by impementing the following in my "Normal.dot" template VBA code:

1) Insert > Class Module
2) Rename "Class1" to "ThisApplication"
3) Paste the following code:
'--- Start of ThisApplication Class Module ---
Option Explicit

Dim objEditBox As CommandBarControl

Public WithEvents objWordApp As Application

Private Sub objWordApp_WindowSelectionChange(ByVal Sel As Selection)
 
   Set objEditBox = CommandBars("FieldEditBar").Controls(1)
   
   If (Sel.Fields.Count > 0) Then
       objEditBox.Text = Sel.Fields.Item(1).Code.Text
   Else
       objEditBox.Text = ""
   End If

End Sub
'--- End of ThisApplication Class Module ---

4) Insert > Module
5) Rename "Module1" to "FieldEditBar"
6) Paste the following code in the module:
'--- Start of FieldEditBar module ---
Option Explicit

' Instatiate the Container class object
Dim objAppClass As New ThisApplication

Dim objEditBox As CommandBarControl

Public Sub AutoExec()
   ' By defining procedure AutoExec, the code will run
   ' automatically when the Addin loads
   ' (automatically load when Word starts)

   Set objAppClass.objWordApp = Word.Application

   Dim objCommandBar As CommandBar
   Dim objCommandBarControl As CommandBarControl
   Dim ToolbarExists As Integer
   
   ToolbarExists = 0

   For Each objCommandBar In Application.CommandBars
       If objCommandBar.Name = "FieldEditBar" Then
           ToolbarExists = 1
       End If
   Next objCommandBar

   If ToolbarExists = 0 Then
       Set objCommandBar = Application.CommandBars.Add("FieldEditBar")
       objCommandBar.Name = "FieldEditBar"
       objCommandBar.Visible = True
   
       Set objCommandBarControl = Application.CommandBars _
           ("FieldEditBar").Controls.Add(Type:=msoControlEdit, id:=1)
       
       Set objEditBox = CommandBars("FieldEditBar").Controls(1)
   
       objEditBox.OnAction = "InsertField"
   End If

End Sub

Function InsertField()
   
   Set objEditBox = CommandBars("FieldEditBar").Controls(1)

   If (Selection.Fields.Count > 0) Then
       Selection.Fields.Item(1).Code.Text = objEditBox.Text
       Selection.Fields.Item(1).Update
   Else
       Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
       objEditBox.Text, PreserveFormatting:=True
       Selection.Collapse (wdCollapseEnd)
   End If

End Function
'--- End of FieldEditBar module ---

This Addin creates an Edit box control on a toolbar that can be docked along
with the other toolbars.  When a selection in the document is highlighted,
the field code is automatically displayed in the box, if the selection
contains a field.  The field code can be modified immediately from the edit
box and is automatically updated upon pressing the Enter key in the edit box.
Typing anything in the edit box creates a new field from the code entered in
the edit box.  

If anyone has a better idea to improve this fonctionality, comments are
welcome.  But so far, this solves my problem.

> My problem is that I find myself performing following (too) many times MS Word:
>
[quoted text clipped - 11 lines]
> pointers where to start to go about implementing this function in Either VBA,
> VB or VC++?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.