SolvedPrivate

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

Posted on 2015-01-30
3
8 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
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

763 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

8 Experts available now in Live!

Get 1:1 Help Now