Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2012, 11:52 PM
NP85 NP85 is offline How do i insert autotext using a contol toolbox checkbox Windows XP How do i insert autotext using a contol toolbox checkbox Office 2003
Novice
How do i insert autotext using a contol toolbox checkbox
 
Join Date: Nov 2012
Posts: 6
NP85 is on a distinguished road
Question How do i insert autotext using a contol toolbox checkbox

I am wanting to use a checkbox from the control toolbox toolbar that when it is checked it will insert an "autotext entry" in a certain location in the document (say for instance a bookmark or similiar)



If someone can help with writing a macro i would really appreciate it.

Thanks
Reply With Quote
  #2  
Old 11-15-2012, 01:48 AM
macropod's Avatar
macropod macropod is offline How do i insert autotext using a contol toolbox checkbox Windows 7 64bit How do i insert autotext using a contol toolbox checkbox Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

The attached document demonstrates the technique. It uses a checkbox titled 'MyCheckBox', a bookmark named 'Destination', and a ContentControlOnExit macro to trigger the updating.
Attached Files
File Type: zip CCtrl ChkBox Text.zip (25.2 KB, 169 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-15-2012, 03:55 PM
NP85 NP85 is offline How do i insert autotext using a contol toolbox checkbox Windows XP How do i insert autotext using a contol toolbox checkbox Office 2003
Novice
How do i insert autotext using a contol toolbox checkbox
 
Join Date: Nov 2012
Posts: 6
NP85 is on a distinguished road
Default

Hi Paul,

Are you able to convert the file into word 2003 format please? The file didnt convert properly from 2007 to 2003.

Cheers,
Reply With Quote
  #4  
Old 11-15-2012, 04:40 PM
macropod's Avatar
macropod macropod is offline How do i insert autotext using a contol toolbox checkbox Windows 7 64bit How do i insert autotext using a contol toolbox checkbox Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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 NP85,

I hadn't noticed that you're using Office 2003. Instead, I infeered from your reference to 'a checkbox from the control toolbox toolbar' that you meant a content control checkbox, which is only applicable to Office 2010 & later.

The attached document demonstrates the technique using a checkbox formfield, which Office 2003 can use. The checkbox is linked to an 'on exit' macro that updates a custom document property named 'ChkState' and a DOCPROPERTY field in the document to reflect the changed content. Do be aware that using formfields requires the use of Word's forms protection, which restricts editing to the filling in of formfields in the document and/or typing in unprotected Sections of the document.
Attached Files
File Type: doc FmFld ChkBox Text.doc (47.5 KB, 53 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-15-2012, 05:41 PM
NP85 NP85 is offline How do i insert autotext using a contol toolbox checkbox Windows XP How do i insert autotext using a contol toolbox checkbox Office 2003
Novice
How do i insert autotext using a contol toolbox checkbox
 
Join Date: Nov 2012
Posts: 6
NP85 is on a distinguished road
Default RE

Sorry to be a pain; I am using a checkbox from the "Control toolbox" toolbar as opposed to the formsfield toolbar on the basis as you mentioned above you need to protect the form when using the formsfield.

Is it possible to do what im trying to do with the "control toolbox" toolbar?

I appreciate your help.

Cheers,
Reply With Quote
  #6  
Old 11-15-2012, 07:41 PM
macropod's Avatar
macropod macropod is offline How do i insert autotext using a contol toolbox checkbox Windows 7 64bit How do i insert autotext using a contol toolbox checkbox Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

OK, here it is with an ActiveX checkbox, using a bookmark named 'Destination', and a macro triggered by clicking on it to do the updating.
Attached Files
File Type: doc ActiveX ChkBox Text.doc (44.0 KB, 86 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 11-15-2012, 09:41 PM
NP85 NP85 is offline How do i insert autotext using a contol toolbox checkbox Windows XP How do i insert autotext using a contol toolbox checkbox Office 2003
Novice
How do i insert autotext using a contol toolbox checkbox
 
Join Date: Nov 2012
Posts: 6
NP85 is on a distinguished road
Default

Thanks heaps thats so awesome!!!


If instead of inserting "Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus" as shown below i want to run a macro i have previously recorded (this macro automatically inserts specific tables and words and i want them to be inserted at the bookmark "destination"), is there a way of calling up the macro within that loop? (the macro names is 'AutoSubdivision')??

Code:
Option Explicit
 
Private Sub CheckBox13534191_Click()
If CheckBox13534191.Value = True Then
  Call UpdateBookmark("Destination", "Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus." & vbCr)
Else
  Call UpdateBookmark("Destination", "")
End If
End Sub
 
Sub UpdateBookmark(BmkNm As String, NewTxt As String)
Dim BmkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    BmkRng.Text = NewTxt
    .Bookmarks.Add BmkNm, BmkRng
  End If
End With
Set BmkRng = Nothing
End Sub

Last edited by macropod; 11-15-2012 at 10:45 PM. Reason: Added code tags & formatting
Reply With Quote
  #8  
Old 11-15-2012, 10:43 PM
macropod's Avatar
macropod macropod is offline How do i insert autotext using a contol toolbox checkbox Windows 7 64bit How do i insert autotext using a contol toolbox checkbox Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Where is your content coming from? And what is the existing code for it?

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 11-15-2012, 10:54 PM
NP85 NP85 is offline How do i insert autotext using a contol toolbox checkbox Windows XP How do i insert autotext using a contol toolbox checkbox Office 2003
Novice
How do i insert autotext using a contol toolbox checkbox
 
Join Date: Nov 2012
Posts: 6
NP85 is on a distinguished road
Default

The content is coming from the normal.dot file and the macro i have recorded (also in the normal.dot file) is:

Code:
 
Sub AutoSubdivision()
    Selection.TypeText Text:="Subdivision"
    Selection.Range.InsertAutoText
End Sub
Reply With Quote
  #10  
Old 11-15-2012, 10:56 PM
NP85 NP85 is offline How do i insert autotext using a contol toolbox checkbox Windows XP How do i insert autotext using a contol toolbox checkbox Office 2003
Novice
How do i insert autotext using a contol toolbox checkbox
 
Join Date: Nov 2012
Posts: 6
NP85 is on a distinguished road
Default

I tried using the code tags but didnt appear to do anything. Apologies for my ignorance.
Reply With Quote
  #11  
Old 11-15-2012, 11:25 PM
macropod's Avatar
macropod macropod is offline How do i insert autotext using a contol toolbox checkbox Windows 7 64bit How do i insert autotext using a contol toolbox checkbox Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Try:
Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
  Call UpdateBookmark("Destination", "Subdivision")
Else
  Call UpdateBookmark("Destination", "")
End If
End Sub
 
Sub UpdateBookmark(BmkNm As String, NewTxt As String)
Dim BmkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    BmkRng.Text = NewTxt
    .Bookmarks.Add BmkNm, BmkRng
    If BmkRng.Text = "Subdivision" Then BmkRng.InsertAutoText
  End If
End With
Set BmkRng = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 02-09-2014, 02:13 PM
skeletor skeletor is offline How do i insert autotext using a contol toolbox checkbox Windows 7 64bit How do i insert autotext using a contol toolbox checkbox Office 2007
Novice
 
Join Date: Feb 2014
Posts: 1
skeletor is on a distinguished road
Default

This thread may be long dead, but hopefully not!

The code modification to allow an autotext entry to be inserted via the ActiveX Checkbox is great.

My question is how to make the autotext disappear if the checkbox is then unchecked after having already been checked. The previous example codes (with plain text instead of autotext) do this, but when modified for autotext it stops this functionality. Any ideas?

Thanks!
Reply With Quote
  #13  
Old 02-09-2014, 03:06 PM
gmaxey gmaxey is offline How do i insert autotext using a contol toolbox checkbox Windows 7 32bit How do i insert autotext using a contol toolbox checkbox Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Here is an adaptation of Paul's code that should work with a named autotext entry stored in the document's attached template:
Code:
Private Sub CheckBox1_Click()
  If CheckBox1.Value = True Then
    Call UpdateBookmark("Destination", "ATEntry" & vbCr)
  Else
    Call UpdateBookmark("Destination")
  End If
End Sub
 Sub UpdateBookmark(BmkNm As String, Optional strATName As String)
Dim BmkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    If strATName <> vbNullString Then
       Set BmkRng = ActiveDocument.AttachedTemplate.AutoTextEntries(strATName).Insert(Where:=BmkRng)
    Else
      BmkRng.Text = vbNullString
    End If
    .Bookmarks.Add BmkNm, BmkRng
  End If
End With
Set BmkRng = Nothing
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i insert autotext using a contol toolbox checkbox Autotext jafrapatty Word 2 05-09-2014 04:30 AM
How do i insert autotext using a contol toolbox checkbox Word 2003 Document Opens In control toolbox Edit Mode rangasamy007 Word 1 09-16-2011 04:12 AM
AutoText question harbor11 Word 0 12-16-2009 09:42 AM
Control Toolbox tjc154 Word 0 03-29-2009 07:13 PM
Excel ->VB code for Checkbox (control toolbox) kirkstyle Excel 0 08-16-2006 04:17 PM

Other Forums: Access Forums

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