[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Fire vb-script from code, Syntax-error

Posted on 2007-07-31
Medium Priority
Last Modified: 2010-04-15
I'm getting a Syntax error in the Internet explorer when I'm trying to fire a vb script from code.
I have coppied the script from an old vb-project, but I must be translating it wrong.
Can anyone help me?

StringBuilder sb = new StringBuilder("");
               sb.Append("\n<script language=vbscript >\n");
               sb.Append("  Dim Word \n");
               sb.Append("  Dim Doc \n");
               sb.Append("Set Word = CreateObject(\"Word.Application\")\n");
               sb.Append("Set Doc = CreateObject(\"Word.Document\")\n ");
               sb.Append("Word.Visible = True \n");
               sb.Append("Set Doc = Word.Documents.Open(\"");
               sb.Append(" \")\n ");
               sb.Append("</script> \n");
this.Page.RegisterStartupScript("Open", sb.ToString());
Question by:staleb
  • 3
  • 2
LVL 96

Expert Comment

by:Bob Learned
ID: 19602175
You don't need to do this to use Word with ASP.NET.

Microsoft Word Documents from ASP.NET


Author Comment

ID: 19603179
I'm not sure thisis the solution
Since this is a web application, And I don't want the users to use Wordl server-side. But I want them to use their local MSWord so that they can edit the document.
If I use a document stored server-side, it will come up write-protected
LVL 96

Accepted Solution

Bob Learned earned 2000 total points
ID: 19603285
Try using Environment.NewLine instead of \n:

 sb.Append("\n<script language=vbscript >" + Environment.NewLine);


Author Comment

ID: 19607515
Here is the script I'm trying to "translate"
script = "<script language=""vbscript"">" & vbCrLf

                script &= "  Dim Word" & vbCrLf
                script &= "  Dim Doc" & vbCrLf
               script &= "  Set Word = CreateObject(""Word.Application"") " & vbCrLf
                script &= "  Set Doc = CreateObject(""Word.Document"") " & vbCrLf
                script &= "  Word.Visible = True" & vbCrLf
                script &= "  set Doc = Word.Documents.Open(""" & sDokNavn.ToString & """) " & vbCrLf
                script &= "  Doc.SaveAs(""" & sDokNavnLokalt & """)" & vbCrLf
                script &= "</script>" & vbCrLf

Author Comment

ID: 19607959
Finally Made it work
Added + Environment.NewLine and altered some security settings in the browser and it worked.
Not quite sure what was the trigger that made it work, but it does work so.. :)

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question