VBA to VBS - iframe permission denied - html

I recently wrote an Excel VBA script to login and navigate an intranet site to download a CSV report. It contains some links and buttons that I need to click inside an iframe. It took some effort to figure out the iframe stuff, but it works. I still don't know how to click "Save" without the download file dialog box being the active window, but that's for another day.
I'm in the process of converting this script to VBS and have run into this error message:
Here are the relevant code snippets:
VBA Code (this works)
Set ie = New InternetExplorer
ie.Visible = True
...
Dim iframeDoc As MSHTML.HTMLDocument
Set iframeDoc = ie.document.frames("fmReports").document
' select the custom report
iframeDoc.getElementById("tvCustomReport").Click
Application.Wait (Now + TimeValue("00:00:03"))
' run the report
iframeDoc.getElementById("btnRunReport").Click
VBS Code (this presents the error dialog above)
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
...
Dim iframeDoc
Set iframeDoc = oIE.document.getElementById("fmReports").ContentWindow.Document
' select the custom report
iframeDoc.getElementById("tvCustomReport").Click
WScript.Sleep 3000 'wait here just in case
' run the report
iframeDoc.getElementById("btnRunReport").Click
Questions/Thoughts
I've turned off just about every security feature I can find in IE.
Are these different domains? (XSS issue perhaps)
The main intranet site url is http://192.168.0.111/app2019 while the contents of the iframe url is http://192.168.0.111/app2018.
Line 49 (referenced in the screenshot) of my full script is the second line in the VBS snippet (Set iframeDoc =...)
Am I missing something obvious?

Related

MS Access - Command button wont function at all

I have tried to Google and review previous Stackoverflow posts but I cannot seem to find a solution and this seems like such a simple fix.
I put a Command button in my Form because i wanted to test exporting information within the form to an Excel spreadsheet.
Private Sub cmdExportFilename_Click()
Dim sFilename As String
sFilename = "C:\Users\Redacted\Desktop\exportResults.xlsx"
DoCmd.OutputTo acOutputQuery, "OpenComplaintsQuery", acFormatXLSX, sFilename, AutoStart:=True
End Sub
I made sure the OnClick event was set to [Event Procedure] but when i go into form view and click nothing happens not even an error so i feel like i am still missing something that is telling that button to run that code. i checked my Trust Center settings and changed it to enable code but still nothing.
Any advice is helpful!

vbScript AppActivate activates random apps

I am trying to write a vb-script to do the following
Launch Chrome
Navigate to a specified website
Loop and keep refreshing that specific tab
I am able to get #1 and #2 to work, using the following code. The refresh works as well. The only issue is that the refresh happens to the windows which are active. The AppActivate part - which is supposed to shift focus to a given window is not working. Code here.
Dim iURL
Dim objShell
iURL = "SampleURL"
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "chrome.exe", iURL, "", "", 1
Do While True
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.AppActivate "Remote Access Asia - Google Chrome"
WSHShell.SendKeys "{F5}"
WScript.Sleep 30000 ' 30 seconds
Loop
The window title I am using was determined by using the tasklist command (tasklist /v /FO:CSV). I have tried using various versions (substrings) of the title shown. I have used chrome.exe as well, but nothing helps. The refresh is not limited to tabs of Chrome - it happens with other apps e.g. notepad as well.
Any thoughts would be much appreciated.
Your code worked fine for a Chrome window I already had open. The issue may be with ShellExecute. I had success using Run and ensuring the site opened in its own window using the --new-window parameter. It's also unnecessary to have the CreateObject inside the While loop. Try it like this:
Set oWSH = CreateObject("WScript.Shell")
URL = "SampleURL"
oWSH.Run "chrome.exe --new-window " & URL
Do While True
oWSH.AppActivate "Remote Access Asia - Google Chrome"
oWSH.SendKeys "{F5}"
WScript.Sleep 30000 '30 seconds
Loop

Open another instance of Access using VBA

I am using a form in Access to open other access databases that perform various different queries that publish reports. As the databases I am opening use a multitude of tables, queries, and reports that have nothing to do with each other it would be awkward and time consuming to link to them all and tedious to make changes inside the original database.
I am using Dim appAccess As Access.Application to open each one. It creates a 2nd instance of the new accdb which will not become visible. However, if I go into view code in the original database and then go back to the form it opens the new instance perfectly visible and will continue to do so as long as I keep the original database open. If I close the original database and reopen it I have the same issue which can only be resolved by viewing the code again.
As an example of what I am using
Option Compare Database
Dim APP As Access.Application
Sub TEST()
Set APP = New Access.Application
APP.Visible = True
APP.OpenCurrentDatabase "C:\Users\Documents\Database1.accdb"
End Sub
Does anyone know why this is happening?
Add line:
APP.UserControl = True
For more info review https://www.devhut.net/2018/01/21/ms-access-VBA-open-another-database/#:~:text=MS%20Access%20VBA%20%E2%80%93%20Open%20Another%20Database%201,to%20truly%20appreciate%20the%20power%20of%20automation.%20

Setting Task Manager to Run VB Script

I have having task manager call up a VB Script which opens an access document at a certain time everyday, and when this document opens it has VBA Code set up to export the file as a different file type. I am getting an error back that will not allow this to run in task manager. I am really confused, because this should be a really easy task it really is creating a new access program opening the document, and then quitting access. I know that the VBA Code in the access file is correct, because it works OK when the file is opened. Task manager is simple so I know it has to be something with my VB script being incorrect(formatting maybe?), because I double click it to run an I get an run error. I would just set task manager to open the access file, but it will not quit access so we went this way. Below is the code in my script.
dim accessApp as variant
set accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("File Location")
accessApp.Quit
set accessApp = nothing
I did a few searches online already with little luck. Any help is greatly appreciated.
You cannot use a type in your Dim statements with VBScript:
dim accessApp
set accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("z:\docs\test.accdb")
''For testing purposes, comment out when testing is finished
msgbox accessapp.name
accessApp.Quit
set accessApp = nothing

How do you extract data from vendor website in vbscript?

I have programmed a post image HTA which is launched after an XP image has been loaded onto a computer. The HTA gathers information from the user (ie primary user name, department, etc) and updates the registry under a custom key. Management has asked if I can pull the computer's warranty information (specifically the warranty end date) from the vendor's website (in this case Lenovo) and update the registry with this info. Lenovo allows anonymous lookup using computer type and serial number and returns a page showing warranty information. Is there a way using vbscript (or maybe javascript?) to parse the returned page for the data I'm looking for?
Thanks in advance,
Gill
Using an HTML parser would probably be a more robust way to do this, but it's easy with VBScript to just script Internet Explorer through OLE Automation.
Dim ie, frm
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www-307.ibm.com/pc/support/site.wss/" & _
"document.do?lndocid=LOOK-WARNTY#sw"
Do Until ie.ReadyState = 4 '' READYSTATE_COMPLETE
WScript.Sleep 100
Loop
Set frm = ie.Document.Forms.warrantyLookup
frm.type.Value = "2644"
frm.serial.Value = "23AB123"
frm.Submit
Do Until ie.Document.ReadyState = "complete"
WScript.Sleep 100
Loop
'' Locate the information you want to scrape from the
'' ie.Document DOM at this point
ie.Quit
You can scrape the page that is returned fairly easily, all it really takes is an HTML parser, and then knowledge of where the information you want is located within the returned page. I do not know of any VBScript HTML parsers, but I am sure they exist. If you cannot find one, however, you can call out to an external program from locally running code, so you could write a page scraping utility in any number of languages (or use some sort of grep utility), and that may do what you are looking for.