SolvedPrivate

Print the page only if a certain word is found on web page

Posted on 2015-01-30
3
9 Views
Last Modified: 2016-02-12
Hi Experts I am using the following code to print data fetched from web search to printer.
Lot of hits are done using pre-defined values. But I need to print only the successful hit only. So the following code needs to be amended to PRINT ONLY IF the page contains the words "Assessment Year". If the word is found then it should print and give a sound. But if the value is not found then it should keep searching till the list is exhausted.

Sub SavePageHTML(doc, strPath, strFileName)
Dim strHTML As String
Dim FF As Long

    If Dir(strPath & "\" & strFileName) = "" Then

        FF = FreeFile()

        strHTML = doc.body.innerhtml

        Open strPath & "\" & strFileName For Output As #FF

        Print #FF, "<link href=""../challan.css"" rel=""stylesheet"" type=""text/css"" />"
        Print #FF, strHTML

        Close #FF

    Else
    
        FF = FreeFile()
        
        strHTML = doc.body.innerhtml

        Open strPath & "\" & strFileName For Append As #FF

        Print #FF, strHTML

        Close #FF
    End If

End Sub

Open in new window

0
Comment
Question by:Kanwal_No2
3 Comments
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 40579801
type this immediately after: strHTML = doc.body.innerhtml
if instr(1,strHTML ,"Assessment Year",1)>0 then 'continue your code...
'if you want the text to be case sensitive then change the last parameter to 0 instead of 1
if instr(1,strHTML ,"Assessment Year",0)>0 then 'continue your code...

Final Code:
Sub SavePageHTML(doc, strPath, strFileName)
Dim strHTML As String, SearchCase As Integer
SearchCase = 1 ' 0= case sensitive, 1=case insensitive

strHTML = doc.body.innerhtml

If InStr(1, strHTML, "Assessment Year", SearchCase) < 1 Then Exit Sub

Dim FF As Long
    If Dir(strPath & "\" & strFileName) = "" Then
        FF = FreeFile()
        Open strPath & "\" & strFileName For Output As #FF
        Print #FF, "<link href=""../challan.css"" rel=""stylesheet"" type=""text/css"" />"
        Print #FF, strHTML
        Close #FF
    Else
        FF = FreeFile()
        Open strPath & "\" & strFileName For Append As #FF
        Print #FF, strHTML
        Close #FF
    End If
End Sub

Open in new window

0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40641327
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

895 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

13 Experts available now in Live!

Get 1:1 Help Now