473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trying to use the GoTo method of the Word.Application ActiveX object in JavaScript


Hi There

I am trying to use the Goto method of the Word ActiveX object. I am
trying to open a document and go to a named bookmark. If I use this
code in VB it works, so I'm sure the approach is possible, I just can't
get JavaScript to work with it.

Here is the code I am using, the error I get from IE is Object
Expected:
Hope someone can help! Any help would be much appreciated

function PageLoad()
{
var WordApp = new ActiveXObject('Word.Application');
WordApp.Visible = true;
var documentlocation = crmForm.all.new_documentlocation.DataValue;
var wd = WordApp.Documents.Open(documentlocation);
wd.Select();
var Name = 'TestFred';
var wr = wd.Selection.GoTo(What : Word.WdGoToItem.wdGoToBookmark,Name :
'TestFred');
}

Dec 11 '06 #1
6 10274

MayBoy wrote:
Hi There
Hi
I am trying to use the Goto method of the Word ActiveX object. I am
trying to open a document and go to a named bookmark. If I use this
code in VB it works, so I'm sure the approach is possible, I just can't
get JavaScript to work with it.

Here is the code I am using, the error I get from IE is Object
Expected:
It would help if you could identify which line, and which part of that
line, in your code is triggering this error.
Hope someone can help! Any help would be much appreciated

function PageLoad()
{
var WordApp = new ActiveXObject('Word.Application');
WordApp.Visible = true;
var documentlocation = crmForm.all.new_documentlocation.DataValue;
var wd = WordApp.Documents.Open(documentlocation);
I am assuming for the sake of argument that you get this far.
wd.Select();
var Name = 'TestFred';
Why have you defined this variable but not used it?
var wr = wd.Selection.GoTo(What : Word.WdGoToItem.wdGoToBookmark,Name :
'TestFred');
This is the line which has a number of possible errors in it.

Error 1
============

"wd" contains a reference to a Document object. The Selection object
is a member of the Application object, not a Document object. So this
should be "WordApp.Selection".

Alternatively, you can call Document.GoTo().

Document.GoTo() : "Returns a Range object that represents the start
position of the specified item, such as a page, bookmark, or field"
Application.Selection.GoTo(): "Moves the insertion point to the
character position immediately preceding the specified item, and
returns a Range object (except for the wdGoToGrammaticalError,
wdGoToProofreadingError, or wdGoToSpellingError constant)."

Errors 2 & 3
============

Firstly, JavaScript does not support NAMED arguments.

So this "GoTo(What : " is a syntax error.

Secondly, you must as a result supply the arguments in the order that
Word expects.

"expression.GoTo(What, Which, Count, Name)"

So you will need to supply default values for Which and Count.
Errors 4 & 5
============

"Word.WdGoToItem.wdGoToBookmark"

There are two errors here:

Firstly, you cannot access the constant wdGoToBookmark as a property of
WdGoToItem.

Secondly, apart from on the Server, you cannot access in JavaScript
Word constants, such as "wdGoToBookmark" by name.

You need to supply the constant value instead. The following is taken
from Word's ObjectBrowser facility in its Macro editor:-

"Const wdGoToBookmark = -1 (&HFFFFFFFF)"
"Const Const wdGoToFirst = 1"

Result
============

Try:-

var myRange = Document.GoTo(-1, 1, 1, 'TestFred');
or
WordApp.Selection.GoTo(-1, 1, 1, 'TestFred');

I have not tested these, so there may be something else to consider as
well. JavaScript does work, with a bit of fiddling.

Regards

Julian

Dec 12 '06 #2
Hi Julian

I tried your answer but still get an error, when you put any value in
for Which it says "You entered multiple destinations for a
page.line.footnoteendnote or comment"

I tried the same in VB and it works with a nothing as the Which and
Count parameters but I can't do that in javascript.

Any ideas?
Julian Turner wrote:
MayBoy wrote:
Hi There

Hi
I am trying to use the Goto method of the Word ActiveX object. I am
trying to open a document and go to a named bookmark. If I use this
code in VB it works, so I'm sure the approach is possible, I just can't
get JavaScript to work with it.

Here is the code I am using, the error I get from IE is Object
Expected:

It would help if you could identify which line, and which part of that
line, in your code is triggering this error.
Hope someone can help! Any help would be much appreciated

function PageLoad()
{
var WordApp = new ActiveXObject('Word.Application');
WordApp.Visible = true;
var documentlocation = crmForm.all.new_documentlocation.DataValue;
var wd = WordApp.Documents.Open(documentlocation);

I am assuming for the sake of argument that you get this far.
wd.Select();
var Name = 'TestFred';

Why have you defined this variable but not used it?
var wr = wd.Selection.GoTo(What : Word.WdGoToItem.wdGoToBookmark,Name :
'TestFred');

This is the line which has a number of possible errors in it.

Error 1
============

"wd" contains a reference to a Document object. The Selection object
is a member of the Application object, not a Document object. So this
should be "WordApp.Selection".

Alternatively, you can call Document.GoTo().

Document.GoTo() : "Returns a Range object that represents the start
position of the specified item, such as a page, bookmark, or field"
Application.Selection.GoTo(): "Moves the insertion point to the
character position immediately preceding the specified item, and
returns a Range object (except for the wdGoToGrammaticalError,
wdGoToProofreadingError, or wdGoToSpellingError constant)."

Errors 2 & 3
============

Firstly, JavaScript does not support NAMED arguments.

So this "GoTo(What : " is a syntax error.

Secondly, you must as a result supply the arguments in the order that
Word expects.

"expression.GoTo(What, Which, Count, Name)"

So you will need to supply default values for Which and Count.
Errors 4 & 5
============

"Word.WdGoToItem.wdGoToBookmark"

There are two errors here:

Firstly, you cannot access the constant wdGoToBookmark as a property of
WdGoToItem.

Secondly, apart from on the Server, you cannot access in JavaScript
Word constants, such as "wdGoToBookmark" by name.

You need to supply the constant value instead. The following is taken
from Word's ObjectBrowser facility in its Macro editor:-

"Const wdGoToBookmark = -1 (&HFFFFFFFF)"
"Const Const wdGoToFirst = 1"

Result
============

Try:-

var myRange = Document.GoTo(-1, 1, 1, 'TestFred');
or
WordApp.Selection.GoTo(-1, 1, 1, 'TestFred');

I have not tested these, so there may be something else to consider as
well. JavaScript does work, with a bit of fiddling.

Regards

Julian
Dec 13 '06 #3
Hi there

I just found out how, just create an empty object and use that.

ie var empty;
var wr =WordApp.Selection.GoTo(-1,empty,0,'TestFred);

Thanks!!
MayBoy wrote:
Hi Julian

I tried your answer but still get an error, when you put any value in
for Which it says "You entered multiple destinations for a
page.line.footnoteendnote or comment"

I tried the same in VB and it works with a nothing as the Which and
Count parameters but I can't do that in javascript.

Any ideas?
Julian Turner wrote:
MayBoy wrote:
Hi There
Hi
I am trying to use the Goto method of the Word ActiveX object. I am
trying to open a document and go to a named bookmark. If I use this
code in VB it works, so I'm sure the approach is possible, I just can't
get JavaScript to work with it.
>
Here is the code I am using, the error I get from IE is Object
Expected:
It would help if you could identify which line, and which part of that
line, in your code is triggering this error.
Hope someone can help! Any help would be much appreciated
>
function PageLoad()
{
var WordApp = new ActiveXObject('Word.Application');
WordApp.Visible = true;
var documentlocation = crmForm.all.new_documentlocation.DataValue;
var wd = WordApp.Documents.Open(documentlocation);
I am assuming for the sake of argument that you get this far.
wd.Select();
var Name = 'TestFred';
Why have you defined this variable but not used it?
var wr = wd.Selection.GoTo(What : Word.WdGoToItem.wdGoToBookmark,Name :
'TestFred');
This is the line which has a number of possible errors in it.

Error 1
============

"wd" contains a reference to a Document object. The Selection object
is a member of the Application object, not a Document object. So this
should be "WordApp.Selection".

Alternatively, you can call Document.GoTo().

Document.GoTo() : "Returns a Range object that represents the start
position of the specified item, such as a page, bookmark, or field"
Application.Selection.GoTo(): "Moves the insertion point to the
character position immediately preceding the specified item, and
returns a Range object (except for the wdGoToGrammaticalError,
wdGoToProofreadingError, or wdGoToSpellingError constant)."

Errors 2 & 3
============

Firstly, JavaScript does not support NAMED arguments.

So this "GoTo(What : " is a syntax error.

Secondly, you must as a result supply the arguments in the order that
Word expects.

"expression.GoTo(What, Which, Count, Name)"

So you will need to supply default values for Which and Count.
Errors 4 & 5
============

"Word.WdGoToItem.wdGoToBookmark"

There are two errors here:

Firstly, you cannot access the constant wdGoToBookmark as a property of
WdGoToItem.

Secondly, apart from on the Server, you cannot access in JavaScript
Word constants, such as "wdGoToBookmark" by name.

You need to supply the constant value instead. The following is taken
from Word's ObjectBrowser facility in its Macro editor:-

"Const wdGoToBookmark = -1 (&HFFFFFFFF)"
"Const Const wdGoToFirst = 1"

Result
============

Try:-

var myRange = Document.GoTo(-1, 1, 1, 'TestFred');
or
WordApp.Selection.GoTo(-1, 1, 1, 'TestFred');

I have not tested these, so there may be something else to consider as
well. JavaScript does work, with a bit of fiddling.

Regards

Julian
Dec 13 '06 #4

MayBoy wrote:
Hi there

I just found out how, just create an empty object and use that.

ie var empty;
var wr =WordApp.Selection.GoTo(-1,empty,0,'TestFred);

Thanks!!
Hi

Good answer. Effectively you are supplying "undefined" as an argument,
which presumably word knows therefore to ignore. Sometimes null also
works, or an empty string.

Best Wishes

Jules

Dec 13 '06 #5
Hi Julian

I tried null and an empty sting but this was the ol=nly solution that
worked.

Hope you have a Merry Xmas!

and Thanks again.

Andy
Julian Turner wrote:
MayBoy wrote:
Hi there

I just found out how, just create an empty object and use that.

ie var empty;
var wr =WordApp.Selection.GoTo(-1,empty,0,'TestFred);

Thanks!!

Hi

Good answer. Effectively you are supplying "undefined" as an argument,
which presumably word knows therefore to ignore. Sometimes null also
works, or an empty string.

Best Wishes

Jules
Dec 14 '06 #6

MayBoy wrote:
Hi Julian

I tried null and an empty sting but this was the ol=nly solution that
worked.

Hope you have a Merry Xmas!

and Thanks again.

Andy
Hi

Merry Xmas to you too. Your undefined variable is a solution I will
make use of myself.

Regards

Julian

Dec 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yuri Vanzine | last post by:
In asp we can run VBSCRIPT client-side which allows for 'easy' :?) ms office COM object instantiation. How do I access a Word object in ASP.NET on the client side? I would like to do spell...
2
by: Ravi J | last post by:
I am trying to load Microsoft Word and create a document in ASP.NET (C#). But the call to application creation 'Word._Application app = new Word.ApplicationClass();' takes quit a bit of time, and...
34
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
12
by: torbs | last post by:
Hi I have a a function with several methods. For simplicity it looks a bit like this: super.prototype.aProperty="HELLO"; super.prototype.returnValue = function () { return 2;
2
by: johnc | last post by:
Hi all Been struggling to get word automation working via ASP on the server. The COM objects etc are installed and there already exists an Excel automation application which works, done by a...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
3
by: JAYO | last post by:
I mean, I've a COM object, as Word.Application. How to implement in a javascript function for using their methods? Thank you in advance.
9
by: VK | last post by:
<OT>I am finishing TransModal 0.1 so planning to move it from alpha to beta stage.<OT> Besides that I am planning to write an introductory to inheritance schema currently used in Javascript...
19
by: David Given | last post by:
I have a situation where I need to use GOTO in a Javascript program. No, I can't use break or continue. Yes, I really do know what I'm doing. What I've got is a huge mass of automatically...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.