Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crop the number of characters in a text string

Status
Not open for further replies.

dnky

Technical User
Sep 11, 2003
21
GB
I'm trying to set up a macro to make custom shows in Powerpoint based on the title slides, the problem is custom show names have a limit of 32 characters.

So if the title string variable contains more than 32 characters, how do I chop off the end.

thank you

 
If Len(VariableName)>32 Then VariableName = Left(VariableName,32)

Hope this helps.
 
Even no test needed:
CustomShowName = Left(TitleSlideName, 32)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV, I realised that as soon as I pressed Submit and didn't think it was worth reposting. [smile]
 
With an elpsis?:

if Len(TitleSlideName) > 32 Then CustomShowName = Left(TitleSlideName, 29) & "..."

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Just my 2 cents worth...Don't forget to clean up any trailing spaces in the truncated string

CustomShowName = trim(Left(TitleSlideName, 32))
 
Works perfectly thanks.

Is there anyway I could trim it at a point where there's a line break too. Or just remove any line breaks?
 
You may play with the InStr or Replace functions.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
For line feed:

CustomShowName = trim(replace(Left(TitleSlideName, 32),chr$(10)," ")))

For carriage return:
CustomShowName = trim(replace(Left(TitleSlideName, 32),chr$(13)," ")))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top