Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

Assign text to String with formatting?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed - 04 Apr 2006 16:25 GMT
Are the commands or switches I can use to directly assign text to a string
within a macro with formatting?  For instance, if I have:
   strText = "This is my text."
can I format it, say, bold so when I write it to a document I get:
"This is my text."

Ed
Jay Freedman - 04 Apr 2006 16:53 GMT
No. A string is just a sequence of characters -- there's nowhere in it to
store any formatting. You must insert the string into the document and then
format it there. IMHO, the best way to do that is with a Range object. For
instance, say you want to insert and format the string after the current
selection:

  Dim strText As String
  Dim rg As Range

  strText = "This is my text."
  Set rg = Selection.Range
  rg.Collapse wdCollapseEnd
  rg.Text = strText
  rg.Bold = True
  Set rg = Nothing  ' cleanup

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Are the commands or switches I can use to directly assign text to a
> string within a macro with formatting?  For instance, if I have:
[quoted text clipped - 3 lines]
>
> Ed
Helmut Weber - 04 Apr 2006 17:03 GMT
Hi Ed,

IMHO, no.
A string is a sequence of bytes.
One could set up a two dimensional array for formatting,
which holds the formatting information for each character,
but I'd say, forget about it.

Would be a nive feature to have.
Not too difficult, but lots and lots of tedious coding.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.