Hail! Experts. I seek thy counsel.
Trying to extract a value from a SAP web application and send a value to a SAP web application (more worried about the first part) from VBA
There are a lot of public declares and functions from other parts of the code that aren't particularly relevant. I've removed the ones that stuck out at me but there may be some extras still there.
Now. My problem...
It doesn't seem to like to getElementbyID and throws me an object required error but I can't see where I haven't got an object specified.
Any assistance or advice from someone with experience in meshing VBA with web apps would be greatly appreciated.
Code as follows
Code:
Option Compare Database
Public crn As String
Public objIEBrowser As Object
Public cfsession As Object
Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Public Const HWND_TOP = 0
Public Const CF_TEXT = 1
Declare PtrSafe Function FindWindow Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As LongPtr
Declare PtrSafe Function SetWindowPos Lib "user32" ( _
ByVal hwnd As LongPtr, _
ByVal hWndInsertAfter As LongPtr, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Function FnLaunchIEBrowser()
Set objIEBrowser = CreateObject("InternetExplorer.Application")
objIEBrowser.Left = 0
objIEBrowser.Visible = True
objIEBrowser.Navigate2 "***obfuscated***"
Do While objIEBrowser.Busy
Loop
hwnd = FindWindow(vbNullString, "Home Page - [Interaction Center ]")
hwnd = SetWindowPos(hwnd, HWND_TOP, 100, 100, 0, 0, SWP_NOSIZE)
apiShowWindow objIEBrowser.hwnd, SW_MAXIMIZE
End Function
Sub allocatecase()
Dim SWs As SHDocVw.ShellWindows, vIE As SHDocVw.InternetExplorer
Dim Count As Integer
Dim NewURL, pcrn As String
Dim doc, element
Dim reading As Object
Dim HWNDSrc As Long
Set SWs = New SHDocVw.ShellWindows
For Each vIE In SWs
If vIE.LocationURL = “” Then
Else
NewURL = vIE.LocationURL
If Mid(NewURL, 8, 7) = "sap-c4p" Then GoTo sessfound
End If
Next
MsgBox "APP session has failed to auto-initialise. Please manually launch a session and maximise it on your left monitor."
GoTo ender
sessfound:
Set cfsession = vIE
Set SWs = Nothing
Set vIE = Nothing
HWNDSrc = cfsession.hwnd
SetForegroundWindow HWNDSrc
Set reading = cfsession.Document.getelementbyid("INPUT_CRN")
pcrn = reading.Value
ender: