Consulting

Results 1 to 5 of 5

Thread: Solved: set reference to Windows Script Host Object Model ???

  1. #1
    VBAX Regular
    Joined
    Jan 2007
    Location
    Dallas area
    Posts
    74
    Location

    Solved: set reference to Windows Script Host Object Model ???

    Looking at a most useful looking KB article (here), the first line of the code states:
    [VBA]''MUST set reference to Windows Script Host Object Model in the project using this code!
    [/VBA]

    I have no doubt that this is true, because the first declaration,
    [VBA]Dim objFSO As FileSystemObject[/VBA]
    chokes for me when I copy the parts of the code I want to use into my project -- says that the User-defined type is not defined. However, I'm utterly at a loss as to HOW to set reference to Windows Script Host Object Model in my project so that things such as FileSystemObject and Folder are valid types which I can use to declare variables.

    Help!

    Thanks,

    G.T.

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by GreenTree
    Help!
    Don't worry! I'll save you!! lol

    When you're in the VBE click Tools --> References --> Windows Script Host Object Model

    Good luck! And Welcome, by the way




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    VBAX Regular
    Joined
    Jan 2007
    Location
    Dallas area
    Posts
    74
    Location
    Many thanks! (thread solved)

    Poking around, I also came across another way to do the same thing (moving and renaming files), this one from a KB article here. The heart of this method is [VBA]Name oldName & "\" & myFile As newName & "\" & myFile[/VBA]
    Obviously, more goes into it, specifying the directory names & so forth; when is this a better method than using the Windows Scripting Host and the File System Object, and when is the latter preferable?

    Thanks!

    G.T.

  4. #4
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    G.T.,

    No problem. Glad to help.

    I prefer Name oldDir As NewDir than FileSystemObject when it comes to moving and renaming files. I typically use FileSystemObject for functions like "FolderExists" or "FileExists" although you can use native VBA to do the same thing I'm pretty sure (and from what I understand it will perform faster).

    I've never used Windows Scripting Host Object before, so I'm sorry I don't have much information on that! (I usually reference Microsoft Scripting Runtime for FileSystemObject) But glancing at the Object Browser between MS Scripting Runtime and WSHO they do have some of the same classes. I'll have to check that out sometime.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  5. #5
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by GreenTree
    Many thanks! (thread solved)

    Poking around, I also came across another way to do the same thing (moving and renaming files), this one from a KB article here. The heart of this method is [vba]Name oldName & "\" & myFile As newName & "\" & myFile[/vba]
    Obviously, more goes into it, specifying the directory names & so forth; when is this a better method than using the Windows Scripting Host and the File System Object, and when is the latter preferable?

    Thanks!

    G.T.
    I would say this is preferable - the name statement's native and when deploying your code you won't run into the problem you had - setting a reference
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •