VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Other Applications Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 03-03-2011, 12:20 PM   #1
ralle123

 
Joined: Mar 2011
Posts: 1
Kb Entries: 0
Articles: 0
help on macro to replace html tags frontpage

trying to create a macro to replace HTML tags in frontpage 2000. Have the following code that works up to some point. I need to look for tags like <td &^&*^> and change them to <td> I also want to look for tags like
<P ALIGN=
"LEFT" DIR="LTR"> and take them out. Tags are not alwas the same so I would look for <p &^&*^*> and take it out. Any ideas?

VBA:
Sub changetags() lngViewMode = Application.ActivePageWindow.ViewMode 'Switch to Normal view. Application.ActivePageWindow.ViewMode = fpPageViewNormal Dim objElement As IHTMLElement Dim strTagName As String Dim strSearch As String Dim strReplace As String 'Doctype strPageHTML = ActiveDocument.DocumentHTML 'td strReplace = "<td>" strSearch = "<td" & "*" & " >" strPageHTML = Replace(strPageHTML, strSearch, strReplace) 'F'ing Microsoft Tags strSearch = "</p>" strReplace = "" strPageHTML = Replace(strPageHTML, strSearch, strReplace) strSearch = "<P ALIGN=" & Chr(34) & "LEFT" & Chr(34) & " DIR=" & Chr(34) & "LTR" & Chr(34) & ">" strReplace = "" strPageHTML = Replace(strPageHTML, strSearch, strReplace) ActiveDocument.DocumentHTML = strPageHTML Application.ActivePageWindow.ViewMode = lngViewMode End Sub
VBA tags courtesy of www.thecodenet.com

Last edited by Aussiebear : 03-11-2011 at 12:59 PM. Reason: Applied VBA tags to code

Local Time: 04:19 PM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Old 11-05-2011, 07:05 PM   #2
jrajul

 
Joined: Feb 2011
Posts: 22
Kb Entries: 0
Articles: 0
I am not an expert in Frontpage, but I have experience in using VBA to manipulate HTML. You will need to modify this code to made the resulting HTML useful to Frontpage (something with which I cannot help you).

This is how I would modify those tag names:

VBA:
On Error Goto error_handler 'The Microsoft HTML Object library must be active (Tools > References) Dim webdoc As MSHTML.HTMLDocument Set webdoc = webbrowser1.Document 'Or set this to your document. 'Variables you will use to refer to the HTML elements Dim elem As MSHTML.HTMLBaseElement Dim newE As MSHTML.HTMLBaseElement Dim myStr As String 'First the controls that you just want to modify: Dim myList As New Collection 'To this list add the tag names of all the types _ 'of elemets that you want to modify (not delete!). myList.Add "TD" myList.Add "Etcetera" For counter = 1 To myList.Count For Each elem In webdoc.getElementsByTagName(myList(counter)) myStr = Replace(elem.outerHTML, elem.innerHTML, "") 'Returns the tag names without all the stuff between. If InStr(1, myStr, " ") Then 'If there is a space in the tag name (indicating a lot of other stuff in the heading tag) then 'Add more restrictive criteria if you need to, so you do not delete to much. Set newE = webdoc.createElement(elem.tagName) 'Create a new element of the same type On Error Resume Next 'Temporarily turn off error handler. newE.innerHTML = elem.innerHTML 'Transplant the guts from the other element On Error Goto error_handler 'Turn error handling back on. webdoc.replaceChild newE, elem 'Replace the bad element with the new one created above Set newE = Nothing 'refresh this variable End If Next elem Next counter 'Now for the controls that must be deleted. Similar process as above Dim myList2 As New Collection myList2.Add "P" myList2.Add "Et cetera" 'Add the tag names that you want to be deleted. For counter = 1 To myList2.Count For Each elem In webdoc.getElementsByTagName(myList2(counter)) myStr = Replace(elem.outerHTML, elem.innerHTML, "") If your_criteria Then elem.RemoveChild 'This function removes elements End If Next elem Next counter Set webdoc = Nothing Set elem = Nothing Set newE = Nothing Exit Sub error_handler: 'Error handler here
VBA tags courtesy of www.thecodenet.com

You will also need to make some modifications to suit your criteria for which tags need modifying.

Local Time: 02:19 PM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 03:19 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express