Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2016, 04:08 AM
PSSMargaret PSSMargaret is offline Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2010 64bit
Novice
Capitalize the first letter in a content control
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default Capitalize the first letter in a content control


I'm using Word 2010. I would like the first letter of my rich text content controls to be capitalized. Is anyone aware of a macro that will do that or any other way?

Margaret
Reply With Quote
  #2  
Old 06-07-2016, 04:56 AM
Charles Kenyon Charles Kenyon is offline Capitalize the first letter in a content control Windows 8 Capitalize the first letter in a content control Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You could likely write a macro to do that. If you have AutoCorrect set to capitalize the first letter in a sentence and there are multiple words it should capitalize the first word assuming it is not already in a sentence.
Reply With Quote
  #3  
Old 06-07-2016, 06:28 PM
macropod's Avatar
macropod macropod is offline Capitalize the first letter in a content control Windows 7 64bit Capitalize the first letter in a content control 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

You could use a ContentControlOnExit macro like:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl
  Select Case .Type
    Case wdContentControlText, wdContentControlRichText, wdContentControlComboBox
      .Range.Characters.First = UCase(.Range.Characters.First)
    Case Else
  End Select
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 06-07-2016, 07:14 PM
PSSMargaret PSSMargaret is offline Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2010 64bit
Novice
Capitalize the first letter in a content control
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

Paul,

Thanks for the code. I understand how to execute an "on exit" macro for legacy fields but how do you implement one for content controls? I don't see it under properties.

Margaret
Reply With Quote
  #5  
Old 06-07-2016, 07:17 PM
macropod's Avatar
macropod macropod is offline Capitalize the first letter in a content control Windows 7 64bit Capitalize the first letter in a content control 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

Simply open the VBE and add the code to your document's 'ThisDocument' code module.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 06-08-2016, 08:45 AM
PSSMargaret PSSMargaret is offline Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2010 64bit
Novice
Capitalize the first letter in a content control
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

Thanks so much. Works great!
Reply With Quote
  #7  
Old 06-08-2016, 10:05 AM
PSSMargaret PSSMargaret is offline Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2010 64bit
Novice
Capitalize the first letter in a content control
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

Actually, had error pop up if I exited the field without entering information. Are you aware of any code to ignore it if no text is entered.
Reply With Quote
  #8  
Old 06-08-2016, 10:11 AM
gmaxey gmaxey is offline Capitalize the first letter in a content control Windows 7 32bit Capitalize the first letter in a content control 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

Code:
    Case wdContentControlText, wdContentControlRichText, wdContentControlComboBox
      On Error Resume Next
      .Range.Characters.First = UCase(.Range.Characters.First)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 06-08-2016, 10:16 AM
PSSMargaret PSSMargaret is offline Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2010 64bit
Novice
Capitalize the first letter in a content control
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

Perfect!!!
Reply With Quote
  #10  
Old 06-08-2016, 10:27 AM
gmaxey gmaxey is offline Capitalize the first letter in a content control Windows 7 32bit Capitalize the first letter in a content control 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

Some people may feel an error statement like that is indiscriminate use of brute force.

Another way to handle that issue is check to ensure the CC is not showing placeholder text.

While it probably doesn't matter in your case, if you had a shape or something anchored in the a rich text control that code my delete the shape.

You could also try:

Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl
  Select Case .Type
    Case wdContentControlText, wdContentControlRichText, wdContentControlComboBox
      If Not CCtrl.ShowingPlaceholderText Then
        .Range.Case = wdTitleSentence
      End If
    Case Else
  End Select
End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #11  
Old 06-10-2016, 07:31 AM
PSSMargaret PSSMargaret is offline Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2010 64bit
Novice
Capitalize the first letter in a content control
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

Thanks Greg. The first code with the error handling worked perfectly. I'm not really understanding the purpose of the last code. Does it affect other content controls besides the rich text control?
Reply With Quote
  #12  
Old 06-10-2016, 11:35 AM
gmaxey gmaxey is offline Capitalize the first letter in a content control Windows 7 32bit Capitalize the first letter in a content control 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

The reason you got the error was because you didn't enter anything into the CC (it was showing placeholder text) so there was no range.characters.first to format.

Error handling can be used to get around that, but another method is to evaluate if the condition exists that caused the error exists and if it does, don't perform the action that causes the error.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #13  
Old 06-13-2016, 11:14 AM
PSSMargaret PSSMargaret is offline Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2010 64bit
Novice
Capitalize the first letter in a content control
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

Thanks for the explanation.

Margaret
Reply With Quote
  #14  
Old 06-15-2016, 04:39 PM
PSSMargaret PSSMargaret is offline Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2010 64bit
Novice
Capitalize the first letter in a content control
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

gmaxey,

The below code you provided has worked perfectly with all of my testinig. The form I'm developing contains rich text content controls. You have to enter a shift+enter for a carriage return for a new paragraph. Is there any code that we can add to this, or separate code, that will assure the first letter of a new paragraph after two shift+enters will automatically be capitalized?

Margaret

Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl
  Select Case .Type
    Case wdContentControlText, wdContentControlRichText, wdContentControlComboBox
      On Error Resume Next
      .Range.Characters.First = UCase(.Range.Characters.First)
      Case Else
  End Select
End With
End Sub
Reply With Quote
  #15  
Old 06-15-2016, 11:34 PM
Guessed's Avatar
Guessed Guessed is online now Capitalize the first letter in a content control Windows 10 Capitalize the first letter in a content control Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,978
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

It is poor practice to use a pair of soft returns instead of a single return. The coding for each (real) paragraph would be much easier too.
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
  Dim aPara As Paragraph
  With CCtrl
    Select Case .Type
      Case wdContentControlText, wdContentControlRichText, wdContentControlComboBox
        On Error Resume Next
        For Each aPara In .Range.Paragraphs
          aPara.Range.Characters.First = UCase(aPara.Range.Characters.First)
        Next aPara
        Case Else
    End Select
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to capitalize first letter after timecode + tab muiy Word VBA 1 06-17-2015 11:03 PM
Capitalize the first letter in a content control Deleting a table from a content control -- preserving the content control BrainSlugs83 Word Tables 8 11-14-2013 03:06 AM
Capitalize the first letter in a content control Only Capitalize First Letter & Delete Last Name zulhfreelancer Excel 5 12-10-2012 07:51 AM
Exceptions for 'Capitalize first letter of sentences' gazpacho Word 1 01-12-2012 11:43 AM
capitalize first letter of sentences norco1 Word 0 06-25-2006 12:37 PM

Other Forums: Access Forums

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