Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 07-05-2022, 10:24 AM
Shmuel G Shmuel G is offline How do I convert a line of text to title case? Windows 10 How do I convert a line of text to title case? Office 2019
Novice
 
Join Date: Jul 2022
Posts: 3
Shmuel G is on a distinguished road
Default

Quote:
Originally Posted by Shmuel G View Post
This technique destroys any character formatting within the selection, such as change of fonts. Is there a simple way to replace the text of the range with the new version, while preserving the original formatting?
It seems that replacing the .Text of each of the Characters in a range, one at a time, will preserve the formatting, but that requires the replacement string to be the same length as the original string.

If not for the trimming and replacement of double spaces, formatting could be preserved by replacing
Code:
.Text = StrTmp
with


Code:
  Dim i As Long
  For i = 1 To .Characters.Count
    .Characters(i).Text = Mid$(StrTmp, i, 1)
  Next
Reply With Quote
  #17  
Old 07-06-2022, 07:19 AM
macropod's Avatar
macropod macropod is offline How do I convert a line of text to title case? Windows 10 How do I convert a line of text to title case? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Did you at least try the code in post #3?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #18  
Old 07-06-2022, 07:40 AM
Shmuel G Shmuel G is offline How do I convert a line of text to title case? Windows 10 How do I convert a line of text to title case? Office 2019
Novice
 
Join Date: Jul 2022
Posts: 3
Shmuel G is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Did you at least try the code in post #3?
Yes, I entered in all the code in post #3 and ran the second snippet on a selection in which some words were in a different font. Character formatting was lost.
Reply With Quote
  #19  
Old 02-21-2023, 05:07 AM
RaymondB7777 RaymondB7777 is offline How do I convert a line of text to title case? Windows 10 How do I convert a line of text to title case? Office 2021
Novice
 
Join Date: Feb 2023
Posts: 2
RaymondB7777 is on a distinguished road
Default

Hi Macropod, I would like to use the code in post #3 to format the text in a text box in a user form. I'm very much a VBA novice so any help would be appreciated.

Thanks
Raymond
Reply With Quote
  #20  
Old 02-21-2023, 04:14 PM
Guessed's Avatar
Guessed Guessed is offline How do I convert a line of text to title case? Windows 10 How do I convert a line of text to title case? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

RaymondB7777

Text in a vba User Form is normally typed in by the user. Are you planning on running this code to re-constitute what the user typed or are you populating the text box in code?

Perhaps you need to attach a document that shows what you already have and what the macro needs to do?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #21  
Old 02-21-2023, 08:37 PM
Charles Kenyon Charles Kenyon is offline How do I convert a line of text to title case? Windows 11 How do I convert a line of text to title case? Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
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

Another note, just so you understand, the first macro was for text in the document, not text in a userform. I am confident that wiser heads than I can adjust for that, but it is a different thing.

If I were doing it, I would need to create a new document, put the text in that document, and then run the code. Then copy the reformatted text from the temporary document, delete that document, and put it in the userform.
Reply With Quote
  #22  
Old 02-22-2023, 12:47 PM
RaymondB RaymondB is offline How do I convert a line of text to title case? Windows 10 How do I convert a line of text to title case? Office 2019
Novice
 
Join Date: Jan 2020
Posts: 1
RaymondB is on a distinguished road
Default

Hi guys, I should have been clearer .

What I want to be able to do is reconstitute what the user typed in the Text Box.

Currently what I use is very simple and works well to change the text in the text box (TextBoxSection) to vbProperCase.

Private Sub TextBoxSection_Change()
Me.TextBoxSection = StrConv(TextBoxSection, vbProperCase)
End Sub

Instead of changing it to vbProperCase, I would like it to format it in line with what Macropod's code does to selected text in the actual document. I have saved that code and have used it successfully in various documents.

Thank you.
Reply With Quote
Reply

Tags
text conversion, title case

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a new TITLE property from text already within document smndnm Word VBA 6 07-04-2014 08:27 PM
Stop review query when small case at beginning of line dsrose Word 2 01-22-2014 12:19 AM
How do I convert a line of text to title case? True Title Case for First Row of All Tables Marrick13 Word VBA 14 12-11-2013 09:12 PM
How do I convert a line of text to title case? Custom Text Filter for this particular case tinfanide Excel 2 09-13-2011 05:08 AM
How do I convert a line of text to title case? From all UPPER CASE to Proper Case davers Word 1 04-30-2009 12:41 PM

Other Forums: Access Forums

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