Solved

Removing a certain tag in an HTML String

Posted on 2002-06-10
9
164 Views
Last Modified: 2010-05-02
Greetings,

I have a variable holding an HTML file content what I want is the following:

Remove all the <a> tags from it, what I want is to capture the link tag and remove it with its contents whatever it is an image , or a text or anything

Please help

thnx
0
Comment
Question by:marounk
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7066424
HTMLString = Replace$(HTMLString,"<a>","") ?
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7066600
also this,
HTMLString = Replace$(HTMLString,"</a>","")

This will remove the hyperlinks from the htm page.

But as I understand from your code is you want to remove all the text within the <a> and </a> tags. If it is so, then find for <a> and </a> tags using mid or instr fns and replace that with vbnullstring(" ")

Hope this helps!

-priya



0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7067592
IMHO, you have two choices:
1) Second one by priya_pbk but changing the first to "<a" since there is not an "<A>" alone ;)
2) You could use HTMLDocument object.
0
 
LVL 1

Author Comment

by:marounk
ID: 7069138
where can I find example on the HTMLDocument Object ???

thnx
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 7070670
One possible solution:
'Set a reference to microsoft Intenet controls
'Set a rteference to microspft html object library
' try this:

Option Explicit

Dim WithEvents IE As InternetExplorer
Dim WithEvents iedoc As HTMLDocument

Dim sContents As String
Private Sub Form_Load()
Set IE = New InternetExplorer
With IE
    .navigate "www.experts-exchange.com/visualbasic/"
    .Visible = True
End With
End Sub


Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
    Set iedoc = IE.document
    Dim lnk As HTMLLinkElement
    For Each lnk In iedoc.links
        lnk.disabled = True
    Next
End If
End Sub
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7072038
Richie, I tried your example, but gives me an error at this line , ie:
lnk.disabled = True

mentions "Object doesn't support this property or method"

I have put the references and wrote down the code, it opens the IE and then shows this error.

Was curious to know how the 'lnk.disabled=true' can actually disable links in a web page!! Am I missing something here.

-priya


0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7072750
I did a test before post it with no problems!
Maybe a MSHTML.dll version problem?

marounk, that code didn't solve your problem?, then, why did you accept my comment as answer?
0
 
LVL 1

Author Comment

by:marounk
ID: 7074756
After adding the Refrences in VB you code did work but it is not finding any Links in any Page !!!

I did close this thread because I was desperate !

Thnx for caring
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7116971
Strange, i did a test with www.experts-exchange.com/visualbasic/ and everything worked fine.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now