PDA

View Full Version : Solved: set reference to Windows Script Host Object Model ???



GreenTree
07-05-2007, 02:31 PM
Looking at a most useful looking KB article (here (http://vbaexpress.com/kb/getarticle.php?kb_id=827#instr)), the first line of the code states:
''MUST set reference to Windows Script Host Object Model in the project using this code!


I have no doubt that this is true, because the first declaration,
Dim objFSO As FileSystemObject
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.

malik641
07-05-2007, 02:47 PM
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 :hi:

GreenTree
07-05-2007, 04:34 PM
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 (http://vbaexpress.com/kb/getarticle.php?kb_id=404). The heart of this method is Name oldName & "\" & myFile As newName & "\" & myFile
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.

malik641
07-05-2007, 07:48 PM
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.

johnske
07-05-2007, 10:09 PM
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 (http://vbaexpress.com/kb/getarticle.php?kb_id=404). The heart of this method is Name oldName & "\" & myFile As newName & "\" & myFile
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 :)