Find and replace text thats not wdAlignParagraphCenter alignment

Im trying to make a macro that set alignment on all text to 
wdAlignParagraphJustify, except text that is wdAlignParagraphCenter.

Right now i have this:
    With ActiveDocument.Content.Find
        .ClearFormatting
        .ParagraphFormat.Alignment = wdAlignParagraphRight
        With .Replacement
            .ClearFormatting
            .ParagraphFormat.Alignment = wdAlignParagraphJustify
        End With
        .Execute Replace:=wdReplaceAll
    End With
    With ActiveDocument.Content.Find
        .ClearFormatting
        .ParagraphFormat.Alignment = wdAlignParagraphLeft
        With .Replacement
            .ClearFormatting
            .ParagraphFormat.Alignment = wdAlignParagraphJustify
        End With
        .Execute Replace:=wdReplaceAll
    End With

This works, but I was hoping for a better solution since there apparently 
exists alot more alignment constants then those two. 
ActiveDocument.Content.Find.ParagraphFormat.Alignment <> 
wdAlignParagraphCenter 
doesnt work.

/Niels
0
Utf
5/25/2010 11:59:01 AM
word.vba.general 1023 articles. 1 followers. Follow

3 Replies
2340 Views

Similar Articles

[PageSpeed] 57

How about

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs
    If oPara.Alignment <> wdAlignParagraphCenter Then
        oPara.Alignment = wdAlignParagraphJustify
    End If
Next oPara


-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



"Tilds" <Tilds@discussions.microsoft.com> wrote in message 
news:744517F6-EAA4-47DF-A9E9-10D7B16EC9C6@microsoft.com...
>
> Im trying to make a macro that set alignment on all text to
> wdAlignParagraphJustify, except text that is wdAlignParagraphCenter.
>
> Right now i have this:
>    With ActiveDocument.Content.Find
>        .ClearFormatting
>        .ParagraphFormat.Alignment = wdAlignParagraphRight
>        With .Replacement
>            .ClearFormatting
>            .ParagraphFormat.Alignment = wdAlignParagraphJustify
>        End With
>        .Execute Replace:=wdReplaceAll
>    End With
>    With ActiveDocument.Content.Find
>        .ClearFormatting
>        .ParagraphFormat.Alignment = wdAlignParagraphLeft
>        With .Replacement
>            .ClearFormatting
>            .ParagraphFormat.Alignment = wdAlignParagraphJustify
>        End With
>        .Execute Replace:=wdReplaceAll
>    End With
>
> This works, but I was hoping for a better solution since there apparently
> exists alot more alignment constants then those two.
> ActiveDocument.Content.Find.ParagraphFormat.Alignment <>
> wdAlignParagraphCenter
> doesnt work.
>
> /Niels 


0
Graham
5/25/2010 12:53:19 PM
On further reflection it will probably be necessary to refresh the screen to 
show the changes immediately, thus

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs
    If oPara.Alignment <> wdAlignParagraphCenter Then
        oPara.Alignment = wdAlignParagraphJustify
    End If
Next oPara
Application.ScreenRefresh


-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
news:htgh7m$6vl$1@news.eternal-september.org...
> How about
>
> Dim oPara As Paragraph
> For Each oPara In ActiveDocument.Range.Paragraphs
>    If oPara.Alignment <> wdAlignParagraphCenter Then
>        oPara.Alignment = wdAlignParagraphJustify
>    End If
> Next oPara
>
>
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
>
> "Tilds" <Tilds@discussions.microsoft.com> wrote in message 
> news:744517F6-EAA4-47DF-A9E9-10D7B16EC9C6@microsoft.com...
>>
>> Im trying to make a macro that set alignment on all text to
>> wdAlignParagraphJustify, except text that is wdAlignParagraphCenter.
>>
>> Right now i have this:
>>    With ActiveDocument.Content.Find
>>        .ClearFormatting
>>        .ParagraphFormat.Alignment = wdAlignParagraphRight
>>        With .Replacement
>>            .ClearFormatting
>>            .ParagraphFormat.Alignment = wdAlignParagraphJustify
>>        End With
>>        .Execute Replace:=wdReplaceAll
>>    End With
>>    With ActiveDocument.Content.Find
>>        .ClearFormatting
>>        .ParagraphFormat.Alignment = wdAlignParagraphLeft
>>        With .Replacement
>>            .ClearFormatting
>>            .ParagraphFormat.Alignment = wdAlignParagraphJustify
>>        End With
>>        .Execute Replace:=wdReplaceAll
>>    End With
>>
>> This works, but I was hoping for a better solution since there apparently
>> exists alot more alignment constants then those two.
>> ActiveDocument.Content.Find.ParagraphFormat.Alignment <>
>> wdAlignParagraphCenter
>> doesnt work.
>>
>> /Niels
>
> 


0
Graham
5/25/2010 1:02:38 PM
That works great! ScreenRefresh wasn't even necessary.
Thank you very much, now it should work for all alignments.

/Niels

"Graham Mayor" wrote:

> On further reflection it will probably be necessary to refresh the screen to 
> show the changes immediately, thus
> 
> Dim oPara As Paragraph
> For Each oPara In ActiveDocument.Range.Paragraphs
>     If oPara.Alignment <> wdAlignParagraphCenter Then
>         oPara.Alignment = wdAlignParagraphJustify
>     End If
> Next oPara
> Application.ScreenRefresh
> 
> 
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
> 
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 
> 
> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
> news:htgh7m$6vl$1@news.eternal-september.org...
> > How about
> >
> > Dim oPara As Paragraph
> > For Each oPara In ActiveDocument.Range.Paragraphs
> >    If oPara.Alignment <> wdAlignParagraphCenter Then
> >        oPara.Alignment = wdAlignParagraphJustify
> >    End If
> > Next oPara
> >
> >
> > -- 
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > Graham Mayor -  Word MVP
> >
> > My web site www.gmayor.com
> > Word MVP web site http://word.mvps.org
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >
> >
> >
> > "Tilds" <Tilds@discussions.microsoft.com> wrote in message 
> > news:744517F6-EAA4-47DF-A9E9-10D7B16EC9C6@microsoft.com...
> >>
> >> Im trying to make a macro that set alignment on all text to
> >> wdAlignParagraphJustify, except text that is wdAlignParagraphCenter.
> >>
> >> Right now i have this:
> >>    With ActiveDocument.Content.Find
> >>        .ClearFormatting
> >>        .ParagraphFormat.Alignment = wdAlignParagraphRight
> >>        With .Replacement
> >>            .ClearFormatting
> >>            .ParagraphFormat.Alignment = wdAlignParagraphJustify
> >>        End With
> >>        .Execute Replace:=wdReplaceAll
> >>    End With
> >>    With ActiveDocument.Content.Find
> >>        .ClearFormatting
> >>        .ParagraphFormat.Alignment = wdAlignParagraphLeft
> >>        With .Replacement
> >>            .ClearFormatting
> >>            .ParagraphFormat.Alignment = wdAlignParagraphJustify
> >>        End With
> >>        .Execute Replace:=wdReplaceAll
> >>    End With
> >>
> >> This works, but I was hoping for a better solution since there apparently
> >> exists alot more alignment constants then those two.
> >> ActiveDocument.Content.Find.ParagraphFormat.Alignment <>
> >> wdAlignParagraphCenter
> >> doesnt work.
> >>
> >> /Niels
> >
> > 
> 
> 
> .
> 
0
Utf
5/25/2010 2:03:01 PM
Reply:

Similar Artilces:

Sorting or aligning columns
I am trying to sort two columns so the data in both of them line up. For example column a will have a, b, c, d, e, f and so on in it. Column B will have a, c,e, f, but missing some of the letters that are in a. How do I line up both of these columns so a lines up with a and b lines up with b and so on. Where there is not a match in both it leave a blank in the second column. Thank You For Your Help Jeremy I saved this from a previous post. Option Explicit Sub testme() Application.ScreenUpdating = False Dim wks As Worksheet Dim ColA As Range Dim ColB As Range ...

Convert Text to number
How can I convert a text field to numeric value? The text values are: < 35 <15 1.5 0.015 >9900 The desired result need to be: 35 15 1.5 0.015 9900 Then in a separate field I need to store the > (Greater than) and < (less than) signs from the same text filed so: < 35 (please note the space between the < and the number 35) <15 (please note that there is no space between < and the number 15) 1.5 0.015 >9900 Will give me: < < (null) (null) > Thank you, Silvio In a query: TheNumber: IIf([TheField]=">...

How to delete text when it only appears in print review Publisher
I have a hidden x that can't be seen to delete it in publisher. It is visable in print review and prints out on paper How to find and remove it Maybe it is on the background. In Publisher 2000 and below, view, background, newer Publisher, view Master page. Do you have the picture detail selected? View, pictures, detailed display. Try selecting sections of the publication, it might become active. Is it a crop mark? If all fails, send the file to me, I'd like to see what is going on... Remove "my" to reply. -- Mary Sauer MS MVP http://office.microsoft.com/ http://msauer.mvp...

quoting selected text in e-mail reply
I have Outlook for Office XP, and I would like to be able to reply to e-mails by quoting selected areas of text from the original message. I can "quote" the entire message and delete certain parts, but I have not been able to select a certain part of the text and reply with just that part quoted. Thanks ...

How to replace column letter in refferences with a function using the old column letter?
Hello How to replace column letter(s) (or column numbers) in refferences with a result of a function using the old column letter(s) (or column numbers)? I think you mean =INDIRECT(A1&7) where A1 holds the letter in this instance. -- HTH Bob Phillips "Dmitry Kopnichev" <kopn@bk.ruDelete> wrote in message news:%23bHpscyzFHA.1968@TK2MSFTNGP10.phx.gbl... > Hello > How to replace column letter(s) (or column numbers) in refferences with a > result of a function using the old column letter(s) (or column numbers)? > > Thanks for your reply. How to change...

How to Synchronize Combo Box with Text Box After Going to Next Rec
I have a combo box called [Title Pick] that I use to display catalog titles to get to the record for that title. I also have a text box, called Title, that shows the title I just selected in the combo box. In addition, I have several navigation buttons used to go to the next record, previous record, etc. After I navigate to a different record using one of these buttons, the text box, Title, has the correct value -- but the Combo Box, [Title Pick], still shows the value from the last time that combo box was used. How do I now get the combo box to show the correct title for that reco...

Function In A Text Box
Hi, I am trying to put a concatenate function in a text box. The error message is as follows: The text you have entered is not a valid reference or defined name. I want to concatenate some text with a number from the cell, A2. Any ideas would greatly appreciated. Regards Tubbsy -- tubbsy ------------------------------------------------------------------------ tubbsy's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=24743 View this thread: http://www.excelforum.com/showthread.php?threadid=388332 Its not a perfect solution but you could perform the concat...

how to find product key for publisher 2007
I lost my box and do not know how to find my product key. I registered my program but now need to load on my laptop. Run the Belarc Adviser on the computer with the product key. http://www.belarc.com/free_download.html -- Mary Sauer http://msauer.mvps.org/ "fibresbuyer" <fibresbuyer@discussions.microsoft.com> wrote in message news:F5EB6F9D-F09D-484F-BAA0-9CD5BC5B2A16@microsoft.com... >I lost my box and do not know how to find my product key. I registered my > program but now need to load on my laptop. ...

Replace Co with Company
I have a [CompanyName] field that I need to replace Co with Company Most of the time Co is at the end of the CompanyName but sometimes it is in the middle of CompanyName Ajax Construction Co Big Construction Co Inc Thank you Be careful. Be very careful. You could use do something as simple, but slow, as open up the table; click on that column, then do a Find and Replace on "co". However (this is the careful part) Construction could come out looking like Companynstruction!!!! So make very sure to back up the entire database and that table before doin...

Outlook (and Word) Spell check original text in reply
I have a couple of my users where Word spell checks original text i reply even though it is marked in tools as Do not Spell Check Origina Text in Reply. If I turn Word off as the editor, then it works fine. This does not occur on all of my machines, only on two... I use Word 2 and Outlook 2K. Any ideas why this is happening? I appreciate the help -- rcstechnologyPosted via http://www.officehelp.in - &lt;a href=&quot;http://www.officehelp.in&quot;&gt;Microsoft Office Software&lt;/a&gt it's because they have a prefix character set. http://www.outlook-tips.net/...

text in downward arc?
Hi there, using publisher i want to create text in a downward arc. i have tried to use the upward arc in the word art section and invert that but the text flips. i want to be able to read it from left to right. No matter how i try the text will not read from left to right? what am i doing wrong? Word art will do that. Which version of Publisher are you using? -- JoAnn Paules MVP Microsoft [Publisher] ~~~~~ How to ask a question http://support.microsoft.com/KB/555375 "ian cobbledick" <ian cobbledick@discussions.microsoft.com> wrote in message news:64D9450C-7416-453...

How to find other attribute value corresponding searced attribute
Header("Item1") returns <MenuItem Content="Open file" Name="Item1" /> How to change this so it returns Content attribute value "Open file" corresponding to Name attribute value ? public static string Header(string entity) { return Menu.Descendants("MenuItem").Where(m => (string)m.Attribute("Name") == entity).Single().ToString(); } Menu type is XElement and it contains: <Menu> <MenuItem Content="File"> <Items> <MenuItem Content="FilemenuSubMen...

search for text then return text
i need a fomula that will search down a specified cells in a column... look at the words in each cell and then display the text i want. for instance... I have a column with words in it and i want it to search through each cell/word for the letter "P"... then i want it to display a "P". if there are one or many instances where a "P" is in that column I want to only display "P". Maybe something like this... =IF(SUMPRODUCT(--(ISNUMBER(SEARCH("P",A1:A20)))),"P","") In this formula case is not a factor. P an...

How do I create a bulk mailing text box in Publisher?
-- Thomas -- Mike Thomas wrote: ...

Meeting requests appearing as text
Hi All, I've googled this problem a lot and not found anything useful. We have a client workstation running XP and Outlook 2003 that finds when they send meeting requests it just comes through as text, not a normal meeting request where you can click accept decline etc. I have sent test messages from his machine to myself (external) and I am also running XP with Outlook 2003. I have found a workaround - when setting up the meeting, go to actions -> forward as ical. But the user shouldnt have to do this should they. Any suggestions? Cheers Chris Hi have a look on this site: F...

Button text #3
I know I can change the text on a button with the following: GetDlgItem(IDC_BUTTON1)->SetWindowText("Enable"); What I would like to know, is it possible to get the text from a button? In other words if by clicking a button I change the text on the button to "Disable" but when clicked again it says "Enable". Can I check to see which it currently is? Thanks GetWindowText(...) but instead I would keep track of that with a boolean variable. m_Button1.SetWindowText(m_ShouldSayEnabled ? "Enable" : "Disable"); AliR. "Ed" <e...

Help, I can't find the right code
I was trying to code using If Then based on a post I read but I think I'm using the wrong code. In my form I want if you answer "yes" to variable 1 then variable 2 must be completed however the code I am currently using required variable 2 to be completed regardless if the answer is "yes" or "no" I am new to access and the world of coding please help! Here is the code I am using: If Not IsNull(Me.Injuries_to_Staff) And IsNull(Me.Explain_Injury) Then Cancel = True MsgBox "Explanation of Injury Is Required" Me.Explain_Injury.SetFocus End I...

Difference between .text and .value property
Hi recently I was trying to create a userform where I was giving the valu of text box to a cell. The textbox value was more that 255 chars and used following method. range("A25").value = txtUpdate.value which then I tested I got a result as #Value error in the cell... I changed the code to range("A25").value = txtUpdate.text and it worked.... can somebody tell me the difference between the above 2.. Thanx in advance Keda -- Message posted from http://www.ExcelForum.com ...

Text Formatting for URL
In CRM, On the accounts form, we would like to have an field point to a portal site where we would keep more information about a client, I have made the field a URL formatting type however it will not show up as a URL just as text. Any help would be greatly appreciated. Stephen Hi, you cannot add a field that is a link. Can you add a button at the top of the window as an alternative? <scrocker@hanebutt.com> wrote in message news:1102372455.314206.323180@c13g2000cwb.googlegroups.com... > In CRM, On the accounts form, we would like to have an field point to a > portal site...

How to keep textbox from covering text when reducing?
When I try to reduce a title textbox that came in a template, it covers up part of the text that is in it. I don't think the text is a separate object from the textbox and I have worked with the formatting over and over and nothing works. Please help me. What template in what version of Publisher? Is the text box part of a group? -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "lhag" <lhag@discussions.microsoft.com> wrote in message news:57C17F65-7CC7-4C88-9B27-A1942B38B224@microsoft.com... > When I try to...

"Outlook Today" button text? And "alt-k" for OLToday?
Office Outlook 2007. Having installed OL2007, I had an "Outlook Today" button available, which had both text and icon on it. Also, clicking "alt-k" while on any page other than OL today brought me there. This morning, I uninstalled Business Contact Manager, because I have no use for it. Having done that, my Outlook Today button vanished. I was able to get it back, but it has only the icon, with no text. That's really not a big deal, except that the button is smaller than I'm used to, and thus not as easy to spot. I'd like the text back with it. Also, al...

Replace zero values with blank
Hi, I have an excel file with demand data per month. It looks something like below but has got 20 000 rows instead of one. 1 0 3 12 3 4 0 10 12 10 11 0 The calculations I need to do on each row are: frequency, median and minimum value. However the calculation needs to be done without zero values. The zero values needs to be replaced by blanks. I have tried CTRL + H to replace the zero values. But it gives me the problem that the zero in 20, 10 etc. gets replaced by blank too. Does any Excel master know how to change all zeros to blanks in a data range? Looking forward on an answer. /Dan...

Copying Text Over Into Multiple Worksheets
I created a form in Word, cut and pasted it into Excel on three different spreadsheets. How can I format the worksheet to copy the text over to the other two worksheets without having to enter text three different times? Sort of like writing on a triplicate form. Is this possible? Please advise and thank you in advance. On the second and third sheets you can have formulae like: =Sheet1!A1 in cell A1, for example. You can repeat this (by copy/paste) in all cells where you require the data to be copied from Sheet1. Hope this helps. Pete The Inquirer wrote: > I created a form in...

Replace or Substitute for COMBIN function
I have lots of lines in this format to convert into COMBIN function (39c3 - 37c3) In the above line I want to convert it to ((COMBIN(39,3)-(COMBIN(37,3)) I have so many lines in the above format. All I want to change the c to COMBIN with values intact as I have give the example. Some of the lines are in this format. (45c6 / (6c5 x (39c1 - 37c1))) The above line should become ((COMBIN(45,6))/((COMBIN(6,5)*((COMBIN(39,1)-((COMBIN(37,1)))))))) Thanks in advance. One way: I assumed you wanted the cells to become a formula. If not, delete the "=" & from the sTe...

Search and Replace in a column
I can't remember how I did this before and not having much success with my syntax. I just want to do a simple search and replace of all dashes in a field with a blank. Table = Vendor Column = PhoneNumber Basically: replace(PhoneNumber,'-','') I just want to strip the - (dash) from the field. What's the easiest way to do this? SQL Server 2005. Thanks, Greg You posted the correct syntax: SELECT REPLACE(PhoneNumber, '-', '') AS phone FROM Vendor; Or if you need to update: UPDATE Vendor SET PhoneNumber = REPLACE(P...