irritating jscript error

M

Matt

I have this code inputted for a button...

function CTRL95_10::OnClick(eventObj)
{
var wdApp; // a general variable
wdApp = new ActiveXObject("Word.Application");
wdApp.Visible = true;
wdApp.WindowState = 1;
//var docObj = null;
wdApp.Documents.Open("C:\Documents and Settings\mattr\Desktop\test.doc");
// wdApp.Quit();
}

The error says that this file cannot be found. This path is correct though.
I have copied it from the path itself. Word opens, but it is blank because of
this error. Anyone know how to put this file inside of it? Thanks!
Matt
 
B

Brian Teutsch [MSFT]

Use "\\" everywhere you want a single "\". The "\" character is special, and
must be escaped when you want "\". Before you yell too much at InfoPath...
or JScript... or Windows... every programming language has some escape
character like this that you just have to know to work around.

Brian
 
M

Matt

Hey Brian,
Thanks for the answer to my problem! I would have never figured that out.
But I have one more question about opening documents. What if I wanted to run
this code for powerpoint? I make the adjustments that seem necessary, but I
get an error that sayd Documents is null or undefined in the line

wdApp.Documents.Open("C:\\Documents and Settings\\mattr\\Desktop\\test.ppt");

What do I need to use instead of Documents? Thanks!
 
B

Brian Teutsch [MSFT]

I don't have PowerPoint's OM documentation in front of me, but:
- does your wdApp object still refer to Word.Application? Using that object
won't work for a .ppt file.
- Check the Developer's section of the PPT help to make sure it's
Application.Documents.Open. It may be Application.Open in PPT.

Brian
 
M

Matt

Thanks Brian! That worked for the path. To make Powerpoint work it must be
powerpoint.application and further down it must be
application.presentations.open(path). Here is a table for office apps:

Microsoft Word -Document
Microsoft Excel -Workbook
Microsoft PowerPoint -Presentation
Microsoft Access -Application

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top