Gasman
Enthusiastic Amateur
- Local time
- Today, 17:56
- Joined
- Sep 21, 2011
- Messages
- 14,235
Hi all,
Would anyone know why this code would jump to what appears a random cell, before it calls the url code?
I have client CMS numbers in an Excel sheet and this code will take me into the CMS charity system with the correct ID.
Sometimes! on first use, it jumps to another cell. I added the activecell part to try and stop that, but it still does it?
I asked on the MrExcel forum a good while back, but received no response.
Would anyone know why this code would jump to what appears a random cell, before it calls the url code?
I have client CMS numbers in an Excel sheet and this code will take me into the CMS charity system with the correct ID.
Sometimes! on first use, it jumps to another cell. I added the activecell part to try and stop that, but it still does it?
I asked on the MrExcel forum a good while back, but received no response.
Code:
Sub CMSConnect()
Dim blnUrlOpen As Boolean
' Now use a function to bypass login page when already logged in
'ActiveWorkbook.FollowHyperlink cstrCMSUrl & ActiveCell.Value, "", False
' Sometimes cell A1 is selected, so check value is numeric
If IsNumeric(ActiveCell.Value) Then
blnUrlOpen = fHandleFile(cstrCMSUrl & ActiveCell.Value, WIN_NORMAL)
Else
MsgBox "Non numeric value " & ActiveCell.Value
End If
End Sub
Code:
'***************Usage Examples***********************
'Open a folder: ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
'Open URL: ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************
Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)
If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
stRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
stRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
stRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function
'************ Code End **********