0

I want to use JavaScript (on a web page) to insert some text into a Microsoft Word document. The Documentation has sample code for VB and C#, but not for JavaScript (JScript). I've been able to figure out a lot of it using code samples as seen here, but certain lines are messing me up.

Here's what I've got so far:

var retText;

var wshShell = new ActiveXObject("WScript.Shell");
var wordApp = new ActiveXObject("Word.Application");
wordApp.Documents.Add();

if (wordApp.Application.Options.Overtype) {
    wordApp.Options.Overtype = false;
}

But when it comes to this line (in C#), I can't quite get at how to translate it:

if (currentSelection.Type == Word.WdSelectionType.wdSelectionIP) 

currentSelection.Type can be translated to wordApp.Selection.Type in my code above, but I'm not sure what to do with Word.WdSelectionType.wdSelectionIP.

Some failed attempts:

alert(wordApp.WdSelectionType); //undefined
alert(new ActiveXObject("Word.WdSelectionType"); //errors out
alert(wordApp.ActiveDocument.WdSelectionType); //undefined    
2
  • For security reasons, you can't do that. Commented Jun 14, 2011 at 1:50
  • @SLaks The security on our intranet is turned way down; we already have some text-inserting code based on the Word.Basic API, but I think I need some features that cannot be used with that one. Or is there a separate security role regarding that WdSelectionType stuff? Commented Jun 14, 2011 at 14:25

1 Answer 1

1

I don't think COM enums are accessible from Javascript.

Instead, you can use the constant's numeric value, which you can find in the VBA object browser.
For readable code, you can make a Javascript variable holdign the value instead of just writing a number.

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

1 Comment

Bummer. Thanks, though; I guess I don't really need to worry too much about it. This object browser is pretty cool, by the way.

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.