Trying to use VBA to execute a javascript command on a webbrowser control
I am trying to execute the command toggletable or showall function on a javascript page that has the tables information hidden until you click on the + button next to it. I would like to just make these automaticly expanded for printing purposes. Here is what I have so far.
Function PrintWebPage()
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_PROMPTUSER = 1
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Dim ie As Object
Dim strWebPage As String, stblAutoNumber(99999) As String, stblBadgeNumber(999999) As String, stblShopNumber(99999) As String
DoCmd.SetWarnings False
' Connect to DB
Set db = CurrentDb()
' Select Statement for scrolling through everyone
sqlString = "SELECT tblPersonal.AutoNumber, tblPersonal.[Badge Number], tblPersonal.Shop , tblPersonal.[Last Name] FROM tblPersonal WHERE tblPersonal.[Shop] = " & """" & ShopUserATMS & """" & ";"
' Sets mRecordset to query the database
Set mRecordset = db.OpenRecordset(sqlString)
' Goes to first record of the generated list
mRecordset.MoveFirst
Do While Not mRecordset.EOF
' Scroll through personal List
stblAutoNumber(i) = mRecordset("AutoNumber")
CheckBadgeNull = mRecordset("Badge Number")
If IsNull(CheckBadgeNull) = True Then
GoTo NoRec:
End If
stblBadgeNumber(i) = mRecordset("Badge Number")
stblShopNumber(i) = mRecordset("Shop")
strWebPage = "https://was3.nnsy.navy.mil/atms/components/supervisor/atms_supv_detail.cfm?BADGE=" & stblBadgeNumber(i)
DoEvents: DoEvents: DoEvents
Set ie = CreateObject("internetexplorer.application")
ie.Navigate strWebPage
Do Until ie.Busy = False
sSleep (1)
Loop
Call ie.Document.parentWindow.execScript("toggletable(Quals)", "JavaSc开发者_开发百科ript")
'ie.getelementsbyid("Showall") = True
'stblShopNumber(99) = ie.Document.execcommand("toggletable", False, Null)
ie.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
sSleep (2)
NoRec:
Loop
ie.Quit
Set ie = Nothing
End Function
It gives me access denied when I use the following command: Call ie.Document.parentWindow.execScript("toggletable(Quals)", "JavaScript")
Any help is appreciated. Beating my head on this one for over 8 hours...
You need to enable "Allow active content to run in files on My Computer" option from Internet Options-->Advanced-->Security. If you want to change this IE setting programmatically, below is the vbscript code for it:
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
dwValue = 0
Set objReg = GetObject("winmgmts:" & "{impersonationLevel=impersonate}\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN"
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath,"iexplore.exe",dwValue
set dwValue to 0 to enable, and 1 to disable the IE setting.
Dim IE As New InternetExplorer
IE.Visible = True
IE.navigate "http://www.google.com"
Do: DoEvents: Loop Until IE.readyState = READYSTATE_COMPLETE
IE.navigate "javascript:alert('hi');"
精彩评论