Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - a stupid question on word.application

Reply
 
Old 03-13-2009   #1 (permalink)
gianbrix


 
 

a stupid question on word.application

Hi,
I am trying to implement a vb script to converting old files automatically.
I decided to use vbscript, but I am new to this scripting language.
I can not call the documents.open method and pass to it the Format and
ConfirmConversions properties.
How is the correct syntax?
On web I fin only the simplest call:
objWord.Documents.Open(filename).
I tried as:
objWord.Documents.Open(filename, ConfirmConversions=False, Format=fmt),
but this gave me errors of type object.
Where I miss something?
thanks

Gianluca


My System SpecsSystem Spec
Old 03-13-2009   #2 (permalink)
Paul Randall


 
 

Re: a stupid question on word.application


"gianbrix" <---***gilucasa***---@xxxxxx> wrote in message
news:X7tul.283953$FR.580278@xxxxxx
Quote:

> Hi,
> I am trying to implement a vb script to converting old files
> automatically.
> I decided to use vbscript, but I am new to this scripting language.
> I can not call the documents.open method and pass to it the Format and
> ConfirmConversions properties.
> How is the correct syntax?
> On web I fin only the simplest call:
> objWord.Documents.Open(filename).
> I tried as:
> objWord.Documents.Open(filename, ConfirmConversions=False, Format=fmt),
> but this gave me errors of type object.
> Where I miss something?
> thanks
You might want to look at the Word Object Model info at msdn.microsoft.com.
http://msdn.microsoft.com/en-us/library/bb216319.aspx

-Paul Randall


My System SpecsSystem Spec
Old 03-13-2009   #3 (permalink)
gianbrix


 
 

Re: a stupid question on word.application

Il 13/03/2009 15.54, Paul Randall ha scritto:
Quote:

> You might want to look at the Word Object Model info at msdn.microsoft.com.
> http://msdn.microsoft.com/en-us/library/bb216319.aspx

I read, but I can not understand this:
Documents.Open FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True


I wrote this, but I get errors:

set oDoc = objWord.Documents.Open FileName:=objFile, Format:=fmt

is equal in vbscript var:=? is not var=?
I am confused
ciao
Gianluca
My System SpecsSystem Spec
Old 03-13-2009   #4 (permalink)
T Lavedas


 
 

Re: a stupid question on word.application

On Mar 13, 10:57*am, gianbrix <---***gilucasa***...@xxxxxx> wrote:
Quote:

> Il 13/03/2009 15.54, Paul Randall ha scritto:
>
Quote:

> > You might want to look at the Word Object Model info at msdn.microsoft.com.
> >http://msdn.microsoft.com/en-us/library/bb216319.aspx
>
> I read, but I can not understand this:
> * * *Documents.Open FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True
>
> I wrote this, but I get errors:
>
> set oDoc = objWord.Documents.Open FileName:=objFile, Format:=fmt
>
> is equal in vbscript var:=? is not var=?
> I am confused
> ciao
> Gianluca
The var:= construct works in Visual Basic for Applications (VBA), but
not in VBScript. In scripting, that arguments are determined strictly
by their order, not by their names (as can be done in VBA). Just
remove the names and it should work ...

set oDoc = objWord.Documents.Open("C:\MyFiles\MyDoc.doc", True)

Note that the arguments of functions (routines that return a value)
must be enclosed in parentheses (while they must NOT have parens for
subroutines).

If the name of the file is in a variable, just substitute that
variable's name, as in ...

sFilename = "C:\MyFiles\MyDoc.doc"
set oDoc = objWord.Documents.Open(sFilename, True)

Also, watch out for the predefined constants. They are not available
to scripting, unless you provide them. This is generally done by
determining their value in the application and providing it in a CONST
statement in the script.

HTH,

Tom Lavedas
==========
My System SpecsSystem Spec
Old 03-13-2009   #5 (permalink)
gianbrix


 
 

Re: a stupid question on word.application

Il 13/03/2009 17.11, T Lavedas ha scritto:
Quote:

> On Mar 13, 10:57 am, gianbrix<---***gilucasa***...@xxxxxx> wrote:
> determining their value in the application and providing it in a CONST
> statement in the script.
>
> HTH,
>
> Tom Lavedas

ok all is clearer Thanks. Only a question:
if the function has for example 10 arguments, and I have to specify the
firs and the last, without the possibility to indicate the parameter's
name, how can I accomplish that?
With the exact numbers of commas in this way?:

funcion(fistParam,,,,,,,,,lastParam)

bye
Gianluca
My System SpecsSystem Spec
Old 03-13-2009   #6 (permalink)
T Lavedas


 
 

Re: a stupid question on word.application

On Mar 13, 12:24*pm, gianbrix <---***gilucasa***...@xxxxxx> wrote:
Quote:

> Il 13/03/2009 17.11, T Lavedas ha scritto:
>
Quote:

> > On Mar 13, 10:57 am, gianbrix<---***gilucasa***...@xxxxxx> *wrote:
> > determining their value in the application and providing it in a CONST
> > statement in the script.
>
Quote:

> > HTH,
>
Quote:

> > Tom Lavedas
>
> ok all is clearer Thanks. Only a question:
> if the function has for example 10 arguments, and I have to specify the
> firs and the last, without the possibility to indicate the parameter's
> name, how can I accomplish that?
> With the exact numbers of commas in this way?:
>
> funcion(fistParam,,,,,,,,,lastParam)
>
> bye
> Gianluca
Yes, that should work.

Tom Lavedas
=========
My System SpecsSystem Spec
Old 03-13-2009   #7 (permalink)
gianbrix


 
 

Re: a stupid question on word.application

Il 13/03/2009 18.40, T Lavedas ha scritto:
Quote:

> Yes, that should work.
>
> Tom Lavedas

ok it works fine!!
Have you got a suggestion to separate filename form its extension?
Is there a dedicated method?
I used
name=right(FileName, -3), but of course extensions are not alwasy of 3
letters as in ".ws".
bye

Gianluca


My System SpecsSystem Spec
Old 03-13-2009   #8 (permalink)
T Lavedas


 
 

Re: a stupid question on word.application

On Mar 13, 2:58*pm, gianbrix <---***gilucasa***...@xxxxxx> wrote:
Quote:

> Il 13/03/2009 18.40, T Lavedas ha scritto:
>
Quote:

> > Yes, that should work.
>
Quote:

> > Tom Lavedas
>
> ok it works fine!!
> Have you got a suggestion to separate filename form its extension?
> Is there a dedicated method?
> I used
> name=right(FileName, -3), but of course extensions are not alwasy of 3
> letters as in ".ws".
> bye
>
> Gianluca
From the WSH documentation ...

Function GetTheBase(filespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
GetTheBase = fso.GetBaseName(filespec)
End Function

See WSH 5.6 documentation download (URL all one line)
http://www.microsoft.com/downloads/d...displaylang=en

Tom Lavedas
=========
My System SpecsSystem Spec
Old 03-13-2009   #9 (permalink)
gianbrix


 
 

Re: a stupid question on word.application

Il 13/03/2009 21.17, T Lavedas ha scritto:
Quote:

>
> See WSH 5.6 documentation download (URL all one line)
> http://www.microsoft.com/downloads/d...displaylang=en
>
> Tom Lavedas

Thanks
It works, but in files as
"firstFile.OfThisYear.txt" this function is not precise.
ok, but at which point I have to delete the fso object?
In the function first of end function?
bye
Gianluca




My System SpecsSystem Spec
Old 03-13-2009   #10 (permalink)
T Lavedas


 
 

Re: a stupid question on word.application

On Mar 13, 4:05*pm, gianbrix <---***gilucasa***...@xxxxxx> wrote:
Quote:

> Il 13/03/2009 21.17, T Lavedas ha scritto:
>
>
>
Quote:

> > See WSH 5.6 documentation download (URL all one line)
> >http://www.microsoft.com/downloads/d...d=01592C48-207....
>
Quote:

> > Tom Lavedas
>
> Thanks
> It works, but in files as
> "firstFile.OfThisYear.txt" this function is not precise.
> ok, but at which point I have to delete the fso object?
> In the function first of end function?
> bye
> Gianluca
I never release objects in my scripts. I know all the manuals do it,
but unless you're short of memory, I don't see the need. Plus, if
they are defined local to a function or subroutine, they're released
when the routine exits. If the WITH construct is used, they are
released at the END WITH statement. Otherwise, they are released when
the script execution ends.

Tom Lavedas
==========
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: stupid question VB Script
Stupid question? Vista General
This may be a stupid question, but here goes... Vista General
Stupid question Vista mail
this is probably a very stupid question Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46