Macro for commenting out columns in table

K

Karl

Hi everyone!
I would like to write a macro that comments out certain columns in a table

Input:

<table>
<tr>
<td>col 1</td>
<td><a href="col2">col 2</a></td>
<td>col 3</td>
<td>col 4</td>
<td>col 5</td>
</tr>
</table>


output:

<table>
<tr>
<td>col 1</td>
<td><a href="col2">col 2</a></td>
<!--
<td>col 3</td>
<td>col 4</td>
<td>col 5</td>
-->
</tr>
<tr>
[...]
</tr>
</table>

I'm new to Visual Basics but a handy Java programmer.
How would a go about? Is there any regexp library I would use to find the
desired columns?
If someone can give me a code snippet to start working with, to sort of kick
me
in the right direction, I'll figure the rest out.

Many thanks
/Karl
 
L

Lisa Wollin \(Microsoft\)

Hi, Karl,

If you know Java, then VBA should be a walk in the park. Since I don't know
exactly how you are expecting your macro to be used, I'm a little uncertain
where to direct you, but I do have a sub that inserts opening and closing
tags around a selection. If you are using FrontPage 2003, this code works
in Code view as well as Design view (to be honest, I really designed it for
2003 and Code view, but I believe it will work in Design view also).

Private Sub SurroundText(TagName As String)
Dim objRange As IHTMLTxtRange
Dim strText As String

On Error GoTo ErrorHandler

ActiveDocument.parseCodeChanges
Set objRange = ActiveDocument.Selection.createRange
strText = objRange.htmlText
strText = "<" & TagName & ">" & strText & "</" & TagName & ">"

objRange.pasteHTML strText
ActiveDocument.parseCodeChanges

ExitSub:
Exit Sub

ErrorHandler:
MsgBox "You need to save your document before you can insert the tag."
GoTo ExitSub

End Sub

You can use this to insert any element that you want. So for example, the
following inserts opening and closing P tags around the selected HTML.

Public Sub PTag()
SurroundText "p"
End Sub

There are several resources to help you get started writing macros. Try the
following on MSDN. In addition, there are several more in other places on
the internet. Just Google for "FrontPage macro". If you need any more
help, feel free to contact me directly at (e-mail address removed).

Automating Repetitive Tasks in FrontPage 2003
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_fp2003
_ta/html/odc_fpAutomatingRepetitiveTasks.asp)
Working with HTML Using the FrontPage 2003 Object Model
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_fp2003
_ta/html/odc_fpworkingwithhtmlprogrammatically.asp)

--
Lisa Wollin
Programmer Writer
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included code samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Karl said:
Hi everyone!
I would like to write a macro that comments out certain columns in a table

Input:

<table>
<tr>
<td>col 1</td>
<td><a href="col2">col 2</a></td>
<td>col 3</td>
<td>col 4</td>
<td>col 5</td>
</tr>
</table>


output:

<table>
<tr>
<td>col 1</td>
<td><a href="col2">col 2</a></td>
<!--
<td>col 3</td>
<td>col 4</td>
<td>col 5</td>
-->
</tr>
<tr>
[...]
</tr>
</table>

I'm new to Visual Basics but a handy Java programmer.
How would a go about? Is there any regexp library I would use to find the
desired columns?
If someone can give me a code snippet to start working with, to sort of kick
me
in the right direction, I'll figure the rest out.

Many thanks
/Karl
 
L

Lisa Wollin \(Microsoft\)

Karl,

I should make one comment. This code will work for most tags. It work work
for the comment tag; however, you can modify it easily enough to work for
the comment tag.

--
Lisa Wollin
Programmer Writer
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included code samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Lisa Wollin (Microsoft) said:
Hi, Karl,

If you know Java, then VBA should be a walk in the park. Since I don't know
exactly how you are expecting your macro to be used, I'm a little uncertain
where to direct you, but I do have a sub that inserts opening and closing
tags around a selection. If you are using FrontPage 2003, this code works
in Code view as well as Design view (to be honest, I really designed it for
2003 and Code view, but I believe it will work in Design view also).

Private Sub SurroundText(TagName As String)
Dim objRange As IHTMLTxtRange
Dim strText As String

On Error GoTo ErrorHandler

ActiveDocument.parseCodeChanges
Set objRange = ActiveDocument.Selection.createRange
strText = objRange.htmlText
strText = "<" & TagName & ">" & strText & "</" & TagName & ">"

objRange.pasteHTML strText
ActiveDocument.parseCodeChanges

ExitSub:
Exit Sub

ErrorHandler:
MsgBox "You need to save your document before you can insert the tag."
GoTo ExitSub

End Sub

You can use this to insert any element that you want. So for example, the
following inserts opening and closing P tags around the selected HTML.

Public Sub PTag()
SurroundText "p"
End Sub

There are several resources to help you get started writing macros. Try the
following on MSDN. In addition, there are several more in other places on
the internet. Just Google for "FrontPage macro". If you need any more
help, feel free to contact me directly at (e-mail address removed).

Automating Repetitive Tasks in FrontPage 2003
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_fp2003
_ta/html/odc_fpAutomatingRepetitiveTasks.asp)
Working with HTML Using the FrontPage 2003 Object Model
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_fp2003
_ta/html/odc_fpworkingwithhtmlprogrammatically.asp)

--
Lisa Wollin
Programmer Writer
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included code samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Karl said:
Hi everyone!
I would like to write a macro that comments out certain columns in a table

Input:

<table>
<tr>
<td>col 1</td>
<td><a href="col2">col 2</a></td>
<td>col 3</td>
<td>col 4</td>
<td>col 5</td>
</tr>
</table>


output:

<table>
<tr>
<td>col 1</td>
<td><a href="col2">col 2</a></td>
<!--
<td>col 3</td>
<td>col 4</td>
<td>col 5</td>
-->
</tr>
<tr>
[...]
</tr>
</table>

I'm new to Visual Basics but a handy Java programmer.
How would a go about? Is there any regexp library I would use to find the
desired columns?
If someone can give me a code snippet to start working with, to sort of kick
me
in the right direction, I'll figure the rest out.

Many thanks
/Karl
 

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