0

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.

3
  • try escaping the quotes with \ e.g. \" Commented Aug 25, 2017 at 8:42
  • 2
    The command that works uses single quotes. The one that doesn't is using double quotes. Have you tried single quotes? Commented Aug 25, 2017 at 9:10
  • 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$GridView1$ctl02$ctl00"", """", true, """", """, false, true))" -All the string arguments shall be within additional double quotes! Thank You All Commented Aug 26, 2017 at 16:28

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.