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 / January 2005

Tip: Looking for answers? Try searching our database.

Formatting part of text in a form field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Debra Farnham - 18 Jan 2005 23:20 GMT
Hi All

Windows 2k
Word 2k

To make a long story short, I have created a userform to complete a Word
Document.  With the use of bookmarks and custom document properties, all is
well.  Where I'm stuck is that a portion of the text in one of the textboxes
on the userform must be returned to Word italiczed.

In attempt to test my ability to extract the text I have used the example in
help as follows:

Dim SearchString, SearchChar, MyFirstHyphen, MySecondHyphen, Phrase
SearchString = "Charge - Highway Traffic Act - description"   ' String to
search in.
SearchChar = "-"    ' Search for "-".

'find first hyphen
MyFirstHyphen = InStr(4, SearchString, SearchChar, 1) + 1

'find second hyphen
MySecondHyphen = InStr(MyFirstHyphen, SearchString, SearchChar, 1) -
MyFirstHyphen - 1

'return phrase between hyphens
Phrase = Mid(SearchString, MyFirstHyphen, MySecondHyphen)

MsgBox Phrase

The above accurately returns the phrase, but I need the phrase to be
italicized.(not onscreen but when it's returned to Word) (I will implement
it properly into my form later)

Any help would be HUGELY appreciated.

Thank you!

Debra
Doug Robbins - 19 Jan 2005 02:23 GMT
Add a \*charformat switch to the Docproperty field and format the D of
Docproperty as italic.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Hi All
>
[quoted text clipped - 38 lines]
>
> Debra
Debra Farnham - 19 Jan 2005 02:28 GMT
Thanks for your response Doug but will that format only a few of the words
that will be inserted or all of them?

TIA

Debra

> Add a \*charformat switch to the Docproperty field and format the D of
> Docproperty as italic.
[quoted text clipped - 41 lines]
> >
> > Debra
Debra Farnham - 19 Jan 2005 04:07 GMT
I think I'm almost there:

Public Sub test()

Dim SearchString, SearchChar, MyFirstHyphen, MySecondHyphen, Phrase, myrange

SearchString = ActiveDocument.CustomDocumentProperties("Offence")   ' String
to search in.
SearchChar = "-"

'find first hyphen
MyFirstHyphen = InStr(4, SearchString, SearchChar, 1) + 1

'find second hyphen
MySecondHyphen = InStr(MyFirstHyphen, SearchString, SearchChar, 1) -
MyFirstHyphen - 1

Phrase = Mid(SearchString, MyFirstHyphen, MySecondHyphen) 'This gets me the
string I want to italicize

***NEED HELP HERE - I'M STUCK ON TRYING TO GET THE DARN PHRASE
ITALICIZED****
Set myrange = Phrase
myrange.Italic = True
***********************
End Sub

Thank you to anyone who might be able to help!

Debra

> Add a \*charformat switch to the Docproperty field and format the D of
> Docproperty as italic.
[quoted text clipped - 41 lines]
> >
> > Debra
Debra Farnham - 19 Jan 2005 13:42 GMT
Not very elegant but this is what I came up with.  Is there a better way?

Dim SearchString, SearchChar, MyFirstHyphen, MySecondHyphen, Phrase

SearchChar = "-"    ' Search for "-".

SearchString = ActiveDocument.CustomDocumentProperties("Offence")   ' String
to search in.

'find first hyphen
MyFirstHyphen = InStr(4, SearchString, SearchChar, 1) + 1

'find second hyphen
MySecondHyphen = InStr(MyFirstHyphen, SearchString, SearchChar, 1) -
MyFirstHyphen - 1

Phrase = Mid(SearchString, MyFirstHyphen, MySecondHyphen)

'Italicize Text

   Selection.Find.Replacement.Font.Italic = True
   With Selection.Find
       .Text = Phrase
       .Replacement.Text = Phrase
       .Forward = True
       .Wrap = wdFindContinue
       .Format = True
   End With
   Selection.Find.Execute
   With Selection
       If .Find.Forward = True Then
           .Collapse direction:=wdCollapseStart
       Else
           .Collapse direction:=wdCollapseEnd
       End If
       .Find.Execute Replace:=wdReplaceOne
       If .Find.Forward = True Then
           .Collapse direction:=wdCollapseEnd
       Else
           .Collapse direction:=wdCollapseStart
       End If
       .Find.Execute
   End With

Debra

> Add a \*charformat switch to the Docproperty field and format the D of
> Docproperty as italic.
[quoted text clipped - 41 lines]
> >
> > Debra

Rate this thread:






 
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.