Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Opening IE and saving page as jpeg or htm with VB

Posted on 2004-08-10
10
Medium Priority
?
359 Views
Last Modified: 2010-05-02
I need a VB sript to open IE to a specific webpage (weather.com) and then save this page as a jpeg or htm (weather.jpeg or weather.htm) and then close IE.  Reasoning behind this is I have users that need to view current weather info but do not have access to internet. This will be displayed on local intranet.   If I have a script then I can set up a scheduled task to run the script and save/replace the image at set intervals.  This will update the intranet webpage giving users what they need without giving any access to the internet or messing with user rights.  Any help would be appreciated.
0
Comment
Question by:Plastic_1
  • 5
  • 5
10 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 11762865
VBSCRIPT can't handle this, it does not interact with a GUI. But if you wish to do something in VB maybe i can help.
What you want "save as jpg" is possible. But the machine that runs the scheduled task may not run a screensaver or anything that blocks the screen. In that case you could use the following :


>>>>>>>>>>>>>>>
Put a picturebox on a VB form and paste the following code :

Private Declare Sub keybd_event Lib "User32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Sub Form_Load()
    TakePicture "http://www.weather.com/", "c:\weather.jpg"
End Sub

Private Function TakePicture(URL As String, Filename As String)
    Dim IE As Object
    Set IE = CreateObject("internetexplorer.application")
        IE.fullscreen = True
        IE.AddressBar = False
        IE.navigate URL
        While IE.busy: DoEvents: Wend
        IE.Visible = True
        IE.StatusBar = False
        IE.ToolBar = False
        While IE.busy: DoEvents: Wend
        keybd_event &H2C, 0, 0, 0
        keybd_event &H2C, 1, 0, 0
        keybd_event &H2C, 1, 0, 0
        DoEvents
        Picture1.Picture = Clipboard.GetData
        IE.Quit
    Set IE = Nothing
        SavePicture Picture1.Picture, Filename
End Function

If this doesn't work out for you then you have to consider extracting the weather text or pictures out of the website.
Just let me know,

Elatik , A
0
 

Author Comment

by:Plastic_1
ID: 11763215
The code works fine but as you mentioned maybe just extracting the radar picture would be nice.
Is it possible to just extract the radar picture from http://www.weather.com/weather/local/USVA0143?from=search_current
0
 
LVL 14

Expert Comment

by:aelatik
ID: 11763562
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Const IMAGE_FILE As String = "http://image.weather.com/web/radar/us_ric_closeradar_medium_usen.jpg"

Private Sub Form_Load()
    ' I am passing the date and time after the URL to avoid loading from cache
    Call URLDownloadToFile(0, IMAGE_FILE & "?ID=" & Now, "c:\temp.jpg", 0, 0)
End Sub
0
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.

 

Author Comment

by:Plastic_1
ID: 11763663
Where do I insert the second part of code into the orginal code?  
0
 
LVL 14

Accepted Solution

by:
aelatik earned 1600 total points
ID: 11763690
This is it :

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Const IMAGE_FILE As String = "http://image.weather.com/web/radar/us_ric_closeradar_medium_usen.jpg"

Private Sub Form_Load()
    ' I am passing the date and time after the URL to avoid loading from cache
    Call URLDownloadToFile(0, IMAGE_FILE & "?ID=" & Now, "c:\temp.jpg", 0, 0)
End Sub

Ignore the previous post, that is another method...
0
 

Author Comment

by:Plastic_1
ID: 11764215
The date and time is not passing correctly because on the second and third runs of the script it pulls the image from cache.

I will up the point because you have been very helpful on this.......
0
 
LVL 14

Expert Comment

by:aelatik
ID: 11764310
How do you know it loaded from the cache ?
0
 

Author Comment

by:Plastic_1
ID: 11764421
I assumed (which is not the appropriate thing to do) that the time stamp from weather.com on the bottom of radar display would stay current with time.  That is incorrect.  It seems they only udate the radar picutre every 20-30 minutes.

Many thanks for your help.  
0
 
LVL 14

Expert Comment

by:aelatik
ID: 11764433
I already thought you looked at the time stamp on the picture :-)
0
 

Author Comment

by:Plastic_1
ID: 11764448
I did look at the time stamp but it did not change with consecutive runs so I assumed it was loading from cache.  That was incorrect.

I increased the points to 400 and accepted your answer.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

782 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