Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 12-05-2021, 02:38 PM
Guessed's Avatar
Guessed Guessed is offline Run VBA code when text box value changes Windows 10 Run VBA code when text box value changes Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

TextBox has a specific meaning which doesn't appear to be what you are looking for in this instance.

Try this:
Set up your document with two Plain Text Content Controls. Set the title of one to "Input Number", set the other title to "Status"
Add this macro to your ThisDocument module
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
  Dim aCC As ContentControl, sMsg As String
  If ContentControl.Title = "Input Number" Then
    If IsNumeric(ContentControl.Range.Text) Then
      If CLng(Trim(ContentControl.Range.Text)) > 100 Then
        sMsg = "In Spec"
      Else
        sMsg = "Out of Spec"
      End If
    Else
      sMsg = "Needs a number greater than 100"
    End If
    For Each aCC In ActiveDocument.SelectContentControlsByTitle("Status")
      aCC.Range.Text = sMsg
    Next aCC
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run VBA code when text box value changes AutoOpen code to change date code to date text Legal Learning Center Word VBA 6 02-22-2020 02:24 PM
Wrap text code not working Bluebell Word VBA 5 03-25-2018 04:26 AM
Run VBA code when text box value changes VBA Code to search for field codes with certain text before the Field code and to change style welcometocandyland Word VBA 4 02-08-2017 06:53 PM
Run VBA code when text box value changes Help with VBA code to find and highlight text mpdsal Word VBA 8 09-11-2014 03:55 PM
Code Request - Text to Columns OTPM Excel Programming 0 02-13-2013 04:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft