Solved

VBScript Object heirarchy

Posted on 2003-10-31
11
703 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
  • 5
  • 4
  • 2
11 Comments
 
LVL 29

Expert Comment

by:leonstryker
Comment Utility
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
Comment Utility
Try this:
oWord.Documents(filename).SaveAs newfilename, fileFormat:=wdFormatDocument   'vba code

Thanks,
~ fantasy ~
0
 
LVL 1

Author Comment

by:Natrous
Comment Utility
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
 
LVL 29

Accepted Solution

by:
leonstryker earned 125 total points
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:Natrous
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now