View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Make an autocorrect entry italic

Bev,

You can use the change event to change the formatting of all the desired words after the entry has
been made in the cell. Create a named range Italicized (your entries currently in sheet1 B1:B???).
Copy the code below, right-click the sheet tab, select "View Code" and paste the code into the
window that appears. The named range Italicized can be dynamic.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myR As Long
If Target.Cells.Count 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Not Intersect(Target, Range("Italicized")) Is Nothing Then Exit Sub

For myR = 1 To Range("Italicized").Cells.Count
If Range("Italicized").Cells(myR).Value < "" Then
If InStr(1, Target.Value, Range("Italicized").Cells(myR).Value) 0 Then
Application.EnableEvents = False
Target.Characters( _
InStr(1, Target.Value, Range("Italicized").Cells(myR).Value), _
Len(Range("Italicized").Cells(myR).Value)).Font.Fo ntStyle = "Italic"
Application.EnableEvents = True
End If
End If
Next myR
End Sub



"Beavy" wrote in message
...
On 28 May, 15:14, "Jim Cone" wrote:
"I would like to make the LongText italic"

I don't believe that is possible using AutoCorrect.
Text formatting in a worksheet cell depends on how the worksheet cell
is formatted, not on how the text is formatted when it is added to the cell.

Worksheets(1).Range("A1").Font.FontStyle = "Italic"
--
Jim Cone
Portland, Oregon USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"Beavy"

wrote in message
Hi there - please excuse my ignorance - I've never used VBA before so
I do need some help!
I would like to make the replacement text into autocorrect formatted
into italic text (as it will be latin text) - I have the following,
Sub CreateLatin()
ItemCount = Application.CountA(Range("Sheet1!A:A"))
For Row = 1 To ItemCount
ShortText = Cells(Row, 1)
LongText = Cells(Row, 2)
Application.AutoCorrect.AddReplacement ShortText, LongText
Next Row
End Sub
However, I would like to make the LongText italic- please help me if
you can, I'd be very grateful.
Regards.


Hi Jim - sorry I seem to have omitted a rather important bit of info -
the autocorrect of the latin names will actually be used in Word - and
I had thought that the autocorrect text could be formatted? There is a
link where a company has done something similar -
http://www.biologicalrecordscentre.g...italicise.html but as
I said, my VBA is effectively NIL - the code above has been snaffled
from a website too! This is a request from one of our staff members
and am trying to see if it can be done as the admin teams have to type
up large field reports full of latin names, so they wish to use a
standardised 3-4 code e.g abk and when they press space , for
Ablepharus kitaibelli (in italics) to come out instead.
Regards,
Bev.