SolvedPrivate

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

Posted on 2015-01-30
3
11 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax error with Dates where clause 10 50
Transposing this formula ... 5 17
simple excel formula 4 18
Formula to run in whole column: 15 16
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,…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

820 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