Solved

VBScript Object heirarchy

Posted on 2003-10-31
11
713 Views
Last Modified: 2008-02-07
I solved my initial question about why I couldn't get Word to save a plaintext file.

 oWord.Visible = TRUE
 oWord.Documents.Open(filename)
 oWord.Documents(filename).SaveAs newfilename, wdFormatText
 oWord.Quit

This didn't work because it had no idea what the heck wdFormatText was. After playing around and throwing some random vals in place of it, I managed to stumble across a value ( 2 ) that worked.

So now my question is, how do I create/declare the object that contains the enumeration so that I can use the wdFormatText instead of using this kludge? At the very least, does anyone have a link or something to details of the enumeration? The msdn site is deplorable when trying to look up that sort of detail on non-.NET technologies.

Thanks,
     - Natrous
0
Comment
Question by:Natrous
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 9660617
Basicly you need to Open the object browser and look up the numeric value of the constant.  In any MS Office application hit Alt + F11 to take yo to the VBA IDE and from there hit F2 to get you into the Object Browser.  Do a search on the constant to look up its value.

Leon
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9667981
Try this:
oWord.Documents(filename).SaveAs newfilename, fileFormat:=wdFormatDocument   'vba code

Thanks,
~ fantasy ~
0
 
LVL 1

Author Comment

by:Natrous
ID: 9670375
Leon - I tried doing what you said, but I couldn't find any objects that had the properties or enumerations I was looking for.

fantasy - VBScript doesn't like that syntax. (I've tried it already)

The main problem I'm having is that I am using vb script and not vb for apps and there's far less good documentation - as far as I can tell - about the former.

Thanks for the ideas,
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Accepted Solution

by:
leonstryker earned 125 total points
ID: 9670404
Then looking at the object browser I get the following for wdFormatText:

Const wdFormatText = 2
    Member of Word.WdSaveFormat

What can't you find?  What do you see in the object browser?

Leon
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9675311
If you want better declaration, then just add the line
Const wdFormatText = 2 'at the top

'Usage
oWord.Documents(filename).SaveAs newfilename, wdFormatText

This is the one method people normally use.
~ fantasy ~
0
 
LVL 1

Author Comment

by:Natrous
ID: 9675635
Ok - my bad...
I finally found the right stuff in the object browser which is great in as much as I can be sure now that I'm saving in plain text as opposed to say, unicode. But, I still would like to be able to initialize, create, or otherwise reference the object by name instead of by using the raw number (which I can't figure out how to initialize in *VBScript* even with the object reference)

So.. if no one can help me find the full answer to my main question in another day or two, I'll give you part of the points for the help in finding the reference.

Thanks,
   - Natrous
0
 
LVL 1

Author Comment

by:Natrous
ID: 9675645
fantasy -
there must be some actual manner of getting access to the object itself instead of hard-coding it
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9675860
Natrous,

You are not really hard coding anything.  The constants you are using are just that, constants.  Somewhere along the line Microsoft designated that wdFormatText = 2, specifically for readability only.  In fact in both VB and VBA you could just as well use  the number 2 instead of wdFormatText and get exactly the same result.  In VBS you can make the same association yourself as fantasy1001 showed, but it is up to you to do so.  

That is one of the limitation of VBS, if you wish to go around it switch to VB or VBA.  Remeber VBS is subset of VBA, which is a subset of VB.  To get more functionality you need to move up the chain.

Leon
0
 
LVL 1

Author Comment

by:Natrous
ID: 9683193
Leon -

I understand what you are saying, but that is what i'm trying to get at. It is hard coding, because I actually need to choose a value. The idea behind VB trying to use all these objects is to create another layer of abstraction (for, among other things, readability). In all the different platforms, all of the constants are simply a number at heart that you can always choose to simply 'hard code' in. I realize all of this, but it is rather sloppy programming. Do I think that some newer release of the Windows Script Host will change the value of this particular enumeration from 2 to 4? Not really. But surrounded by so many other (albeit weak) object representations, it seems out of place and kludgy.

I assumed that since there were so many other objects open to use with VBScript, and since I can use the functions that are described in reference to these enumerations, I must be having some lack in syntax that I could not uncover. That was - and is - still my question. If in fact it is simply MSDN describing older functions with new references, then I am not entirely surprised. I was just trying to bring the level of the scripts as high as possible within the constraints of the system. Evidently I cannot use an object reference in this case, but at least now I will stop looking.

Thanks again for all the help,
 - Natrous
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9683375
Natrous,

I do not think we will see a much different version of WSH, in fact I would not be suprised if it will go away rather soon.  In its place we will be using full blown VB.NET.  ASP.NET has already dropped VBS and as far as M$ is concerned it is only the begining.

Leon
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9689959
Natrous,

I just noticed a file called ADOVBS.inc which looks like a list of constants for VBS to use.  It looks something like this;

<%
'--------------------------------------------------------------------
' Microsoft ADO
'
' Copyright (c) 1996-1998 Microsoft Corporation.
'
'
'
' ADO constants include file for VBScript
'
'--------------------------------------------------------------------

'---- CursorTypeEnum Values ----
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3

'---- CursorOptionEnum Values ----
Const adHoldRecords = &H00000100
Const adMovePrevious = &H00000200
'
' And so on
%>

I think you may be able to find or create a similar file for your Outlook VBS scripts and include the file for WSH to refernce it as it comes across those variables.  

Leon
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

623 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