I have an excel application that I want to prompt the user to log into the local sharepoint site. I can't interact directly with sharepoint so I want to bring up a standard message box asking to log in. User selects Yes and excel brings up IE and navigates to the site. At this point IE is the focus window. What I'd like to happen is for Excel to just sit there and wait until it's the active window again. Then move on with the macro. I keep getting into infinite loops or locking up excel in some other way. I get Excel to Not Respond like it's my job. Anyway here's my code:
In the This Sheet code module I have (which I think is probably wrong):
Then in the regular code module, Module 2, I have:
Any help at all would be greatly appreciated! Thank in Advance
In the This Sheet code module I have (which I think is probably wrong):
Code:
Public Sub Application_Change(ByVal mse As Excel.Application)
If Not mse.hasFocus Then
isExcelActive = False
Else
isExcelActive = True
End If
End Sub
Then in the regular code module, Module 2, I have:
Code:
Public isExcelActive As Boolean
Sub MySub()
Application.DisplayAlerts = False
Select Case MsgBox(Prompt:="Do you need to login to SharePoint?", Title:="Login to Sharepoint", Buttons:=vbYesNoCancel)
Case vbYes
Dim ieBrowser As Object
Set ieBrowser = CreateObject("InternetExplorer.Application")
ieBrowser.Visible = True
ieBrowser.Navigate2 "My_URL" 'the URL is irrelivent here. It works up to this point.'
Dim dt As Date
Do
dt = DateAdd("s", 30, DateTime.Now)
Do While dt > DateTime.Now
If isExcelActive <> False Then
GoTo Skip
End If
Loop
Loop Until isExcelActive = True
ieBrowser.Quit
Exit Sub
Case vbNo
GoTo Skip
Case vbCancel
GoTo SkipSP
End Select
Skip:
'Some Code Stuff'
SkipSP:
'More Code Stuff'
Application.DisplayAlerts = True
End Sub
Any help at all would be greatly appreciated! Thank in Advance
Last edited: