I made a custom class library in Excel that uses the "Windows UIAutomationClient" to automate some processes at work (Mostly automating vendor websites). Edge somewhat works ok, but seems to have compatibility issues with the invoke pattern on several sites. Using chrome on my home PC seems to resolve the issue, but I can't seem to get chrome to launch with accessibility enabled at work. Inspect.exe shows the webpage as one big element when I'm at my desk. I'm thinking there may be some UAC restriction at play. I'm attempting to launch chrome using the "--force-renderer-accessibility" flag to try and get around it, but can't seem to get it to work. Here is the current code:
Enum uiBrowserType
Chrome = 0
Edge = 1
End Enum
Public Function launchBrowser(urlTxt As String, browserType As uiBrowserType) As Long
Dim filePath As String, cFlags As String, myUrl As String, dblShellReturned As Boolean
If browserType = Chrome Then
filePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
cFlags = " -url --force-renderer-accessibility "
End If
If browserType = Edge Then
filePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
cFlags = " -url --force-renderer-accessibility "
End If
On Error Resume Next
dblShellReturned = Shell(filePath & cFlags & urlTxt, vbNormalFocus)
Err.Clear
If dblShellReturned = True Then
launchBrowser = 1
Else
launchBrowser = 0
End If
End Function
Am I doing anything wrong? Or does anyone have any alternative suggestions?
Oh and our IT Security departments official policy is as follows:
"Any request for access to any system; For any reason; Is a serious security risk and will be denied. Even if you need it to do your job. Now go away and stop bothering me."
So getting them to help isn't exactly an option. ¯_(ツ)_/¯
Related
Currently, my VBA code is able to verify if a file exists or not. If it exists, it opens the file and replaces all instances of "Test" with "Hello". If it does not exist, it sends a message stating so. My problem is that upon opening the file (in this instance a Word document), it may take several seconds and the code returns a "run-time error". Is there a way I can wait for the application to fully open until proceeding? I have tried the "Application.Wait" method, but it is not so reliable, since the file may take more than a second. Additionally, I have seen other forums suggest using WScript.Shell instead, but is there a way I can use the type in my code?
If strFileExists = "" Then
MsgBox "The selected file doesn't exist"
Else
Set objShell = CreateObject("shell.application")
objShell.ShellExecute strFileName, "", "", "open", 3
Application.Wait (Now + TimeValue("00:00:01"))
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="Test", ReplaceWith:="Hello", _
Replace:=wdReplaceAll
Set objShell = Nothing
End If
You can use Windows API FindWindowExA or FindWindowA functions to solve your problem (I suppose you're using Windows). BTW, I've implemented API solution for the same problem at my work (cannot provide the code, as I am not at my work desktop and on Linux, ATM).
Find what the window title is (just open the file and type the title you see in the title bar). Usually, it consists of a file name and the name of the application (e.g., my_file.docx - Word or my_file - Word). Then, put FindWindowExA or FindWindowA function into While or Until loop. Pass the window title to the function. Once, the window with the specified title is found, exit the loop.
I am working on a macro which open internet explorer, login on site and then work on that. Macro is working fine till login and shows error at "MON". There are some other issues:
Macro is working fine while debugging (using f8) but when run it with F5 an error gets pop up "type mismatch error 13" for "MON". Can someone please suggest what would be the reason for this?
While defining Mon what definition would be perfect to use?
Is there any other way of selecting from the drop down list on the Internet explorer.
It would be of great help if anyone can provide the code for switching to opened Internet Explorer without using shell.
We have also used extra waiting time too like "1 min" but the issue still exist.
Sub Intex()
Set ie = Createobject("internetexplorer.application")
ie.visible = ture
ie.navigate Range("URL").Value
Application.wait(now + timevalue("00:00:15"))
Set Login_Id = ie.document.getelementbyid("LoginID")
Login_id.value = ****
Set Login_pass = ie.document.getelementbyid("Password")
Login_pass.value = ****
ie.document.form(0). submit
Application.wait(now + timevalue("00:00:15"))
Set Mon= ie.document.getelementbyid("ddlReportingMonth")
For i= 0 to Mon.options.length
If Mon.Options(i).Text = Range("Rep_Mon").value
Mon.selectindex = i
Exit For
End If
Next i
Thanks in advance
Instead of waiting a set amount of time for the page to load
Application.wait(now + timevalue("00:00:15"))
try using the following lines:
Do While ie.busy
Loop
that should help with your error when trying to set the Mon variable
I have checked similar issues, but the solutions I have seen don't really address this problem. I am trying to temporarily change the file access of a linked Excel sheet for a supervisor on a network drive. After doing some testing, I was able to validate that 2 directories I was testing are recognized. However, when trying to set a workbook object to a particular .xlsx file in those folders, I kept getting an error indicating Excel couldn't find the file (note the exact Excel name was copied and pasted in). Here is a sample of the code:
Dim wb As Excel.Application
Dim s As String
If Me.Check9.Value = False Then
s = CurrentPath & "\OurFile.xlsx"
Else
s = "\\--UserProfile---Data\My%20Documents\Access%20Database%20Work"
End If
If Dir(s, vbDirectory) = "" Then
MsgBox ("Good")
Excel.Application.EnableEvents = False
s = s & "\DummyQueryTested.xlsx"
'*** Here is where the error is; we disabled macros above ***'
Set wb = Workbooks.Open(s)
wb.ChangeFileAccess Mode:=xlReadWrite
Else
MsgBox ("Bad")
Set wb = Workbooks.Open(s)
End If
Excel.Application.EnableEvents = True
A few last notes:
There are On_Open macros, so that is why I tried using the EnableEvents=False command. The thought was those were preventing the files from opening
I can't just move the file to another location because this is a file that is opened by an Access database as a link, and the company needs these files to be in the locations they are currently residing in.
Finally, you can see I tested the network as well as local file paths and that is what the "Check9.Value" test was for...to test 2 different filepaths.
Any help would be appreciated. I have seen similar issues, but not exactly like this one. Is there any way to test further if there is some permission, or some setting these files have that might be causing problems?
I have Microsoft Access Runtime not full version of Microsoft Access, When i create object in Excel VBA
Set objAccess = CreateObject("Access.Application")
That time i am getting
Error 429 "ActiveX component can't create object."
Suggest how to create object?
I'm not sure whether this information is still relevant to OP, but it might help out others (like me) who were looking for a solution:
In cases where the simple route
Dim AccApp as Object
Set AccApp = CreateObject("Access.Application")
doesn't work (e.g. because only the Runtime Version of Access is available), the following route seems to work:
Const PathToDBFile as String = "W:\here\Your\DB\lies.accdb"
Const PathToAccess as String = "C:\Program files\YourOfficeVersion\MSACCESS.EXE"
Dim ShellCmd as String
' Piece together the parts (yes, the quotes are necessary in case there are spaces in the paths)
ShellCmd = """" & PathToAccess & """ """ & PathToDBFile & """"
' Execute the command in the shell
VBA.Shell ShellCmd
' Now GetObject can return the newly created instance of Access
Dim AccApp as Object
Set objAcc = GetObject(PathToDBFile)
(Source)
This code is only the bare bones to show the essential steps. One likely wants to make sure there isn't already an instance of Access running. Also I've not yet worked out how I can reliably get the path to the MSAccess.exe on different systems. But the above worked for me when I tried on a system with only the Runtime Version installed. (I was able to get the correct return from AccApp.Run "MyFunction".)
Currently I am using the below code to close all the browsers except the ALM browser from where I run the test suite from. However When I run the suite from ALM, the below code identifies 2 browsers - ALM browser and the test case browser. It first closes the test case browser and when it executes the iteration for the ALM browser, it says the browser is not identified when it tries to find the name of the browser. I am not sure why it counts it as a browser if it cant identify it later. Any thoughts on how to resolve this?
Dim oBrDes
Dim oBrObjList
Dim objIndex
Set oBrDes=Description.Create
oBrDes("micclass").Value = "Browser"
Set oBrObjList=Desktop.ChildObjects(oBrDes)
N = oBrObjList.count-1
For objIndex=0 to N
If(oBrObjList(objIndex) is nothing) then
'Do Nothing
Else
name = lcase(oBrObjList(objIndex).GetROproperty("name"))
If (Instr(1,name,"quality center") <> 0 or Instr(1,name,"automatic runner") <> 0 or name <> "") then
value = oBrObjList(objIndex).getroproperty("visible")
If(trim(value) <> "True") then
'Do Nothing
Else
oBrObjList(objIndex).close
End If
End If
End If
Next
Set oBrObjList=Nothing
Set oBrDes=Nothing
Another option is to use ALM explorer.
Check this link for more information.
By using this you do not need to worry about closing any browser.
In Tools ⇒ Options ⇒ GUI Testing ⇒ Web there is an Ignore ALM checkbox, this may be interfering with the Browser identification. Try setting/unsetting this checkbox and see if this solves your problem.