Macro to tab indent space indented HTML

G

GoCoogs

I've worked for about an hour trying to figure out a way

<table>
<tr>
<td>
<table>

to be

<table>
<tr>
<td>
<table>

I'm trying to format lots of source code.

Any ideas?
 
D

Doug Robbins - Word MVP

It's not really clear from your discription and example whether you want to
replace leading spaces with the same number of tab spaces or remove them,
but either way, you can do it by copying and pasting the code into a Word
document and then use Edit Replace, then copy and paste the code back into
the editor.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

GoCoogs

I am trying to replace the spaces with the same number of tabs. I tried
taking the code from Dreamweaver, putting it into WORD and writing a
macro but I had trouble.

I had trouble having the macro ignore ALL spaces within < > and only
replacing spaces immediately after a linebreak ^13 and before a < with
the same number of tabs.
 
R

Russ

You can use find and replace to apply highlight or some other formatting to
'distinguish' parts of the document you want to ignore, like the "<*>" and
then attack the rest of the undistinguished parts of the document by telling
find and replace to only find, for instance, unhighlighted text patterns.
When you are done attacking, remove your highlighting or whatever special
formatting you used.

You don't have to try to cram it into just one find and replace pattern.
 
R

Russ

You can use find and replace to apply highlight or some other formatting to
'distinguish' parts of the document you want to ignore, like the "<*>" and

I should have used "\<*\>" as an example to escape the < >
characters and make them literal characters and not wildcards for
searching.
 
D

Doug Robbins - Word MVP

The following should do it:

Dim i As Long, j As Long, k As Long, tabstring As String
Dim apara As Paragraph
With ActiveDocument
For k = 1 To .Paragraphs.Count
tabstring = ""
i = InStr(.Paragraphs(k), "<")
If i > 1 Then
For j = 2 To i
tabstring = tabstring & vbTab
Next j
.Paragraphs(k).Range = tabstring & LTrim(.Paragraphs(k).Range)
End If
Next k
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top