-
Feb 16th, 2009, 08:19 AM
#1
Thread Starter
Junior Member
Word VBA Paragraph formatting
Hi All,
I am using word VBA. I have created my own styles. The document we are working will have formats such as bold, italic, underline, subscript, superscript etc,. While applying my styles in the author document, existing formats are getting changed. I want to retain all the existing formats while applying styles. Is it possible???
Ex:
In this chapter, we will look at the simplest form of constitutive equa-tions for fluids having no viscous stress. To expand our range of applica-tions further, we will then extend the concept of invicid flow to include po-tential flow and unidirectional incompressible flow.
Thanks,
Senthil.
-
Feb 16th, 2009, 09:12 AM
#2
Lively Member
Re: Word VBA Paragraph formatting
Do you mean you want to apply the format to a specific word (not to the whole document)?
Perhaps it would help if you posted the code with which you tried to do the job. Shouldn't be too hard to fix it, I presume.
Please be kind enough to RATE a helpful post.
-
Feb 16th, 2009, 03:18 PM
#3
Re: Word VBA Paragraph formatting
try recording a macro, then check out the generated code
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 16th, 2009, 11:59 PM
#4
Thread Starter
Junior Member
Re: Word VBA Paragraph formatting
Hi,
Code:
Option Explicit
Private Sub Styling()
Dim oPara As Paragraph
ActiveDocument.Styles.Add Name:="Sample", Type:=wdStyleTypeParagraph
ActiveDocument.Styles("Sample").AutomaticallyUpdate = False
For Each oPara In ActiveDocument.Paragraphs
oPara.Range.Select
Selection.Style = "Sample"
Next oPara
End Sub
While executing the above code if the para has already having formats such as italic, bold, underline etc,. then it got changed to normal while applying style.
Para before applying style:
The Adenovirus (Ad) is currently being evaluated as a cancer therapy agent for a wide variety of tumor types, including brain tumors. Shortly after its isolation in the 1950s, it was demonstrated that the Ad has in vitro oncolytic.
Para after applying style:
The Adenovirus (Ad) is currently being evaluated as a cancer therapy agent for a wide variety of tumor types, including brain tumors. Shortly after its isolation in the 1950s, it was demonstrated that the Ad has in vitro oncolytic.
Thanks,
Senthil.
-
Feb 18th, 2009, 07:50 AM
#5
Addicted Member
Re: Word VBA Paragraph formatting
why not try to find the word you want to change the style or formatting, then if it finds the word apply the style..
here's the code..
Code:
Sub styledoc()
Dim strfind As String
strfind = InputBox("Type the string to change formatting")
With Selection.Find
.Text = strfind
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = True
End With
Selection.Find.Execute
Selection.Font.Bold = wdToggle ' bold the text
Selection.Font.Italic = wdToggle ' change to italic
Selection.Font.Underline = wdUnderlineSingle
End Sub
pls. don't forget to rate helpful post...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|