VEERAMANI K
VEERAMANI K

Reputation: 19

VBA for running javascript in IE

I am tyring to run JavaScript through VBA in Excel.

IE.document.parentWindow.execScript "javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Edit$0')"

The above code works fine.

I am tyring to click another link through following code which is running a JavaScript. But I am getting an "expected end of statement" error.

IE.document.parentWindow.execScript "javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$GridView1$ctl02$ctl00", "", true, "", "", false, true))"

I have also tried using double quotes " like

""ctl00$ContentPlaceHolder1$GridView1$ctl02$ctl00"" 

The error has gone but it did not run the script.

Upvotes: 0

Views: 1690

Answers (1)

VEERAMANI K
VEERAMANI K

Reputation: 19

I got it. The existing code is

IE.document.parentWindow.execScript "javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$GridView1‌​$ctl02$ctl00", "", true, "", "", false, true))" 

Now the working code is

IE.document.parentWindow.execScript "javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(""ctl00$ContentPlaceHolder1$GridView‌​1$ctl02$ctl00"", """", true, """", """, false, true))"

-All the string arguments shall be within additional double quotes! Thank You All

Upvotes: 1

Related Questions