Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
SolvedPrivate

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

Posted on 2015-01-30
3
Medium Priority
?
14 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 2000 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 49

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

730 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