testing url string

  • Thread starter Thread starter thomas donino
  • Start date Start date
T

thomas donino

I have a macro that works fine except sometimes the website comes up with
another logon screen. How can I test for a specific url string to see if
thats the current webpage address, so that if it is , I can resend the
user/pass .

Thank you
 
Thomas,

This is code from Tim Williams. The function returns an object, so if it
returns Nothing then the IE window containing the URL is not found;
otherwise, the reverse is true. (Notice that the function uses the Like
operator, so keep that in mind).

Best,

Matthew Herbert

'******************************
'Find an IE window with a matching (partial) URL
'Assumes no frames.
Function GetIE(sAddress As String) As Object

Dim objShell As Object, objShellWindows As Object, o As Object
Dim retVal As Object, sURL As String


Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

'see if IE is already open
For Each o In objShellWindows
sURL = ""
On Error Resume Next
sURL = o.document.Location
On Error GoTo 0
If sURL <> "" Then
'Debug.Print sURL
If sURL Like sAddress & "*" Then
Set retVal = o
Exit For
End If
End If
Next o

Set GetIE = retVal
End Function
'******************************
 
Matthew,

Thank you. I will try it. On another topic. Once the IE window is open and
displaying the pdf's I open, how do you send print commands to it specifying
which printer to use other than using the sendkeys commands? I tried using
the acrobat shell but that wont work on a pdf open in an explorer window.
 
thanks to both of you


Steve Yandl said:
Here is an alternate approach

'-----------------------------------

Sub CheckMyURL()
Dim strURL As String

strURL = "http://www.google.com/"

On Error Resume Next
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.Open "GET", strURL, False
objHTTP.Send

If objHTTP.statusText <> "OK" Then
MsgBox "Possible problem with the URL"
Else
MsgBox "URL checks out"
End If

Set objHTTP = Nothing

End Sub

'-----------------------------------

Steve Yandl
 
Thomas,

I haven't had to print from the IE window itself nor have I had to specify a
printer other than the Default Printer; however, I did some searching and it
appears that I came across some code that may help you.

The ExecWB Method (see the msdn link below, which has separate links to the
constants) will execute your print command. Application.ActivePrinter will
allow you to specify the desired printer. There is code below which uses the
previously posted GetIE function. Obviously, you'll need to change the code
below to reflect the appropriate URL, print constants for ExecWB, and printer
name.

Note: It appears that the name of the printer has a ":" at the end of the
text, e.g. the printer dialog shows my printer as HPLJ4100 but
Application.ActivePrinter reveals "HPLJ4100 on Ne04:". Maybe you are more
familiar than I am about printers -- I know that printers print and that's
about it -- so if my next comment is not new information, please ignore it.
One way to get the correct printer name would be to change your default
printer and then do one of the following:
(1) in the Immediate Window (View | Immediate Window), type
?Application.ActivePrinter [and then hit <Enter>]
(2) run a sub with this syntax
Debug.Print Applcation.ActivePrinter [which will print to the Immediate
Window].

http://msdn.microsoft.com/en-us/library/aa752117(VS.85).aspx

I hope this helps.

Best,

Matt

Sub PrintIEWindow()

Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_PROMPTUSER = 1
Const OLECMDEXECOPT_DONTPROMPTUSER = 2

Dim objIE As Object
Dim strCurrentPrinter As String
Dim strDesiredPrinter As String

'get the current printer, so that it can be reset
' when the print command is finished
strCurrentPrinter = Application.ActivePrinter '"text name:"

'specify the printer to print to
strDesiredPrinter = "xxx:"

'set the specified printer
Application.ActivePrinter = strDesiredPrinter

'get the IE window
Set objIE = GetIE("http://www.google.com/")

'print the IE window
objIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER

'change the printer back
Application.ActivePrinter = strCurrentPrinter

End Sub
 
Back
Top