PDA

View Full Version : A Real tough one..



Lucy234
03-02-2012, 06:07 PM
I know this is a tough one, but I must give it a shot.

I don't know how it is called, perhaps a section of the text?

How to make the bolded examples always with the one TAB inside?


XXXX XXXXX XXXXX XXXX XXXX XXXX XXX XXXX XXX
XXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXX.

XXXX XXXXX XXXXX XXXX XXXX XXXX XXX XXXX XXX
XXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXX.

XXXX XXXXX XXXXX XXXX XXXX XXXX XXX XXXX XXX
XXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXX.

So at the each beginning of the section the first letter of the word would be capitalized, and the word itself would be one TAB from the left. If there are any periods or multiple tabs before, they would be reduced to 0 and then just one TAB to the right.

I know this is hard, but perhaps someone could know. Ty so much.

macropod
03-02-2012, 06:59 PM
Hi Lucy,

What your post depicts appear to be paragraphs of one or two lines, possibly with an empty paragraph between them. Bolding the first word of each paragraph is easy enough, using a wildcard Find/Replace, but your post is far from clear as to where these tabs and periods are, as there is no indication of them in your post. Perhaps you could attach a document with some representative content, showing what you're trying to achieve (ie with before and after depictions of the same data)?

Lucy234
03-03-2012, 01:20 AM
Hi Lucy,

What your post depicts appear to be paragraphs of one or two lines, possibly with an empty paragraph between them. Bolding the first word of each paragraph is easy enough, using a wildcard Find/Replace, but your post is far from clear as to where these tabs and periods are, as there is no indication of them in your post. Perhaps you could attach a document with some representative content, showing what you're trying to achieve (ie with before and after depictions of the same data)?

Nono, I don't want to BOLD those words, I've just marked them to be more easily visible. I just want the first word of each paragraph to be ONE TAB from the left like in the example I've put in the doc here. I've also bolded those words to be more visible, I don't want them bold in any case. So the first Word in each paragraph should be ONE TAB from the left and if there are "spaces" before or "10 tabs" it should all auto delete and become ONE TAB from the left to the inside like in the example I've uploaded here.

macropod
03-03-2012, 02:13 AM
What you're describing for the first lines is best done via first-line indents than by tabs. And that is what you already have! To do that properly, you don't need any macros - all you need is to define and apply a suitable paragraph Style. As for any unwanted tabs and spaces at the start of each paragraph, that can easily be taken care of with a very ordinary Find/Replace, where:
Find = ^p^w
Replace = ^p

Lucy234
03-03-2012, 02:47 AM
What you're describing for the first lines is best done via first-line indents than by tabs. And that is what you already have! To do that properly, you don't need any macros - all you need is to define and apply a suitable paragraph Style. As for any unwanted tabs and spaces at the start of each paragraph, that can easily be taken care of with a very ordinary Find/Replace, where:
Find = ^p^w
Replace = ^p

Oh boy..there is no way I can do that..I need to make TAB for the each beginning of the paragraph. The example I've attached already has those TABS, I need macro for the situation where it doesn't and I want 1 TAB from the left for each paragraph..
To recognize automatically for every document where does the paragraph begin (especially if there is no space before the first word of the paragraph) and to automatically delete space+tab (if there are any) and put 1 TAB.

Lucy234
03-03-2012, 02:55 AM
Here is the second example where there is no TAB before the beginning of the first word of the paragraph (which are bolded to be noticed easily).

I need something to automatically recognize them and move them one TAB from the left, for every document and situation (not just this one).

Lucy234
03-03-2012, 03:07 AM
Btw, ^13 to replace with ^13^t is not an option because it messes everything up.

or ^p instead of ^13

Lucy234
03-03-2012, 03:25 AM
I don't want to add tab after numbering as well..something that won't affect numbering

macropod
03-03-2012, 03:47 AM
If you want help, kindly do as I asked in post #2 in this thread, stop wasting time and post a document with truly representative before and after samples. So far, what you've described hasn't matched the documents you've posted and, even with the latest additional criteria, could be done with a wildcard Find/Replace, where:
Find = ^13([!0-9^13]{2,4}[!^13]@^13)
Replace = ^p^t\1

Lucy234
03-03-2012, 07:21 AM
If you want help, kindly do as I asked in post #2 in this thread, stop wasting time and post a document with truly representative before and after samples. So far, what you've described hasn't matched the documents you've posted and, even with the latest additional criteria, could be done with a wildcard Find/Replace, where:
Find = ^13([!0-9^13]{2,4}[!^13]@^13)
Replace = ^p^t\1

This command doesn't work for me, it says nothing is found. I will post 2 documents here. One before alteration and the second one after (how it should look like). Here it goes.
I know it's complicated but I would really like to know how to accomplish this, ty..

Lucy234
03-03-2012, 07:21 AM
And here is the After one..how it should look like..

macropod
03-03-2012, 01:50 PM
This command doesn't work for me, it says nothing is found.In which case, either:
• you didn't do a wildcard Find/Replace; or
• your data is nothing like what's in your previous attachment.
In any event, in post #8 you implied that some paragraphs are numbered. Yet your supposedly representative samples have no such content.
FWIW, the wildcard Find/Replace I suggested works with all your attachments. To clean up the unwanted spaces at the start of various lines, all you need to do beforehand is an ordinary Find/Replace, where:
Find = ^p^w
Replace = ^p
With both sets of Find/Replace expressions, everything except the first paragraph will be processed. To get it to process all paragraphs, simply insert a temporary empty paragraph at the top.

Finaly, despite repeatedly saying you want tabs, your 'after' document has none - it uses first-line indents, which is what I suggested before.

fumei
03-03-2012, 02:10 PM
These paragraphs are appalling bad. If you used styles - the way Word is designed to be used - then you would not have these issues in the first place. It is far better to do things right, to start with, rather than a ridiculous amount of work trying to fix the poor usage of Word shown here.

Really, I am VERY curious. How do you get these paragraphs like this in the first place?????

Lucy234
03-03-2012, 11:03 PM
Ok, maybe in the after document you don't see TABs but first line indents, but I need TABs nevertheless.
Ok, The command can remove all space before paragraph, but how to insert TABs afterwards?

macropod
03-04-2012, 12:01 AM
Since you're determined to ignore our advice about Styles, you can use the two sets of Find/Replace expressions I've already given.

1. Insert an empty paragraph at the start of the document.
2. Do an ordinary Find/Replace, where:
Find = ^p^w
Replace = ^p
3. Do a a wildcard Find/Replace, where:
Find = ^13([!0-9^13]{2,4}[!^13]@^13)
Replace = ^p^t\1
4. Delete the document's first paragraph.
If you want, you can record it as a macro for future use.

Lucy234
03-04-2012, 12:35 AM
Since you're determined to ignore our advice about Styles, you can use the two sets of Find/Replace expressions I've already given.

1. Insert an empty paragraph at the start of the document.
2. Do an ordinary Find/Replace, where:
Find = ^p^w
Replace = ^p
3. Do a a wildcard Find/Replace, where:
Find = ^13([!0-9^13]{2,4}[!^13]@^13)
Replace = ^p^t\1
4. Delete the document's first paragraph.
If you want, you can record it as a macro for future use.

This is how it looks like:

http://imageshack.us/f/696/withoutwildcard.jpg/

http://imageshack.us/f/828/withwildcard.jpg/

macropod
03-04-2012, 01:21 AM
If you'd told us you're using a system with non-english regional settings, that would have helped - as would telling us what the error message is. The fix is quite simple: change the ',' character in the Find expression to ';'.

Lucy234
03-04-2012, 02:33 AM
If you'd told us you're using a system with non-english regional settings, that would have helped - as would telling us what the error message is. The fix is quite simple: change the ',' character in the Find expression to ';'.

OK, this is what I use and works good:

Sub rem()
'
' rem Macro
'
'
Selection.WholeStory
With Selection.ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.FirstLineIndent = InchesToPoints(0)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p^w"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^13([!0-9^13]{2;4}[!^13]@^13)"
.Replacement.Text = "^p^t\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

End With
End Sub

Thank you for your assistance.

macropod
03-04-2012, 08:26 PM
Your code can be simplified and made far more efficient as:
Sub Demo1()
Application.ScreenUpdating = False
With ActiveDocument.Range
.InsertBefore vbCr
With .ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.FirstLineIndent = InchesToPoints(0)
End With
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p^w"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
.Text = "^13([!0-9^13]{2;4}[!^13]@^13)"
.Replacement.Text = "^p^t\1"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
.Characters.First.Delete
End With
Application.ScreenUpdating = True
End Sub
When posting code, please use the VBA tags.

BoatwrenchV8
03-05-2012, 02:56 PM
If you'd told us you're using a system with non-english regional settings, that would have helped - as would telling us what the error message is. The fix is quite simple: change the ',' character in the Find expression to ';'.

Macropod - How did you know the system being used was a Non-English regional version? Was it because of the error the comma caused in the find and replace box? Isn't the comma considered the list separater in the English version? Checked my system with using "msgbox Application.International(wdListSeparator)
" in the immediate window and it said "," is it. On the right track with how you deduced the problem??

macropod
03-05-2012, 03:54 PM
Macropod - How did you know the system being used was a Non-English regional version? Was it because of the error the comma caused in the find and replace box?
Yes. Since the F/R worked just fine for me, and Lucy's error message said the expression was invalid, the only reasonable explanation was that her system requires a ';' separator.

Isn't the comma considered the list separater in the English version?Yes, but Lucy's system evidently isn't the English version.