Hello,
I'm trying to figure out how, if I have my cursor in a table cell, to select all text in the cell that has "Normal" style applied and apply Body Text style.
Can anyone give me a pointer?
Thanks!
Hello,
I'm trying to figure out how, if I have my cursor in a table cell, to select all text in the cell that has "Normal" style applied and apply Body Text style.
Can anyone give me a pointer?
Thanks!
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
I think that this will work for my purposes... far from the most efficient, I'm sure, but satisfactory.
[vba]Sub ChangeStyle()
Dim lWord As Long
For lWord = 1 To Selection.Words.Count
If Left(Selection.Words(lWord).Style, 6) = "Normal" Then Selection.Words(lWord).Style = "Body Text"
Next lWord
End Sub[/vba]
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Hi Ken,
You would probably be better off using Find and Replace. Just record yourself to get some basic code.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Hi Tony,
Not being really familiar with the Word model... can you do a find/replace on Styles?
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Sorry Tony! Found it!
Go figure the neat stuff they hide in all those little boxes!
Cleaned up version of (necessary) recorded code:
[vba]With Selection
.Find.Style = ActiveDocument.Styles("Normal")
.Find.Replacement.Style = ActiveDocument.Styles("Body Text")
.Find.Execute Replace:=wdReplaceAll
End With
[/vba]
Will still need to edit it to be appropriate to cell only, though.
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Haven't tried this but it should work with ..
With Selection.Cells(1).Range.Find
The Find object can be a bit funny with Ranges sometimes (or maybe I just haven't got a proper grip on it).
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Hi Tony,
Ah! Now cells... I can work with those! LOL!
Worked a treat, my friend. Thank you very much.
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!