Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I understand that there are 2 ways of formatting in word: direct-formatting, where you select a text,pick the font, size, colour, alignment etc. Other is style-based formatting, where you select the text, and if you find a suitable style, then just apply that style. I am converting a bad inconsistent directly-formatted document into consistent style-based formatted document in word 2007.

In headings, there are spaces entered in the left to get the alignment of the text a bit to the right. Say, I want to get rid of these manual blank spaces and apply an existing heading 3 style. When I do it, I see the font/colour/size changing as per the style, but the spaces remain as such. I want those spaces to go away and heading to start from the left-most.

What should I do?

share|improve this question
up vote 2 down vote accepted

You will have to delete the spaces as these are plain characters and not formatting.

You could write a macro to do the conversion which could trim he heading and convert the style. As to details of how to do this I would write the first macro by recording the steps. Probably along the lines of:

  1. Start on a header row which needs trimming both ends
  2. Start recording a macro
  3. Go to beginning of line
  4. Select spaces with keys
  5. Delete spaces
  6. Select new style
  7. end recording
  8. Edit macro to remove absolute references

Now, I suspect there is a better way as changing text could be done with a trim function but my knowledge of Word VBA is limited and I always start with a recored macro.

I sympathise as I have had to do this for a several hundred page document.

share|improve this answer
    
Can you post how to write this macro. I would do this on Vim/gVim but it would lose some formating because Vim handles only plain text. This question got my interest as sometimes I need to make bigger changes on Word and it ends up generating to much pain to do. – Johnny Feb 17 '11 at 11:18

After you've set the styles, you can remove all the trailing spaces at the beginning of paragraphs by doing a search and replace operation. If you replace ^p^w with ^p, that will do the trick. (^p means paragraph mark, ^w means whitespace)

Note that this removes all trailing whitespace, including tabs, from all paragraphs: so if you have other lines that you want to start with whitespace this is not going to help.

share|improve this answer

You can search for formatted text, too, at least in Word 2010/11 (sorry, no 07/08 at hand). Try and combine this with the regular expression.

First change all headings you want to the level 3 style. Then apply Biglig's regular expression search or rather "^p {1,4}", formatted as 'level 3' - " " are not forbidden in regular expressions. That should work unless Word manages to mangle the headings with the previous paragraph.

I'm not sure whether you see a single space or several. If the headings consistently begin with, say, 3 or 4 spaces and they are the only paragraphs with that 'manual style', you may try to search for "^p {1,4}" then apply the 'level 3 heading' paragraph style to the text.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .