Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime Error 5: Invalid procedure call or argument

Status
Not open for further replies.

9August84

Programmer
Apr 15, 2009
8
0
0
IN
Hi all,
I am trying to extract the texts from a web page and write it to a text file.
I am able to read the text by using internetexplorer.application but when I try to write it to the notepad sometimes it gives Runtime Error 5: Invalid procedure call or argument.
Microsoft VB Help says that it happens bcoz of "An argument probably exceeds the range of permitted values."

Can someone help me to get rid of this problem.

Thanks in advance.
 
The code is
Code:
Sub GetTextFromIe()

Dim NPOFile$, myFile$
Dim ie As Object, objDoc As Object, f As Object, fs As Object
Dim strURI As String

strURI = "[URL unfurl="true"]www.google.com"[/URL]

Set ie = CreateObject("internetexplorer.application")
ie.Navigate strURI

'Wait for page to load!
Do
If ie.ReadyState = 4 Then
ie.Visible = False
Exit Do
Else
DoEvents
End If
Loop

Set objDoc = ie.Document

strMyPage = objDoc.body.innerText


'Use this Text file!

Dim FileSave
FileSave = Application.GetSaveAsFilename("Contents-" & Format(Date, "dd-mm-yy") & "-" & Format(Time, "hh") & "-" & Format(Time, "nn") & "-" & Format(Time, "ss"), "Text Files (*.txt),*.txt")
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile(FileSave, True)
myFile = FileSave

NPOFile = "NotePad.exe " & myFile

'Work with file [Append Text to File].
f.Write (strMyPage)
f.Close

'Open NotePad with a data file!
ActiveSheet.Select

Call Shell(NPOFile, 1)

Set objDoc = Nothing
Set ie = Nothing
End Sub

The line f.Write (strMyPage) gives me the error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top