SolvedPrivate

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

Posted on 2015-01-30
3
13 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 48

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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 …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

634 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