Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Using Wscript.Shell in Word VBA?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed - 10 May 2006 16:14 GMT
I'm attempting to use Wscript.Shell through Word 2002 VBA to access a
shortcut's TargetPath.  Actually, right now I'm just attempting to set an
object to Wscript.Shell!!  I have a reference to the Windows Script Host
Object Model library (wshom.ocx).  I'm using the following code just to try
and get a handle on using this, but it keep throwing "Error 424 - object
required" on the Set line.  Can anyone give me a boost?  Or an alternate
method?

Ed

Sub GetDesktop()

Dim WshShell
Set WshShell = Wscript.CreateObject("Wscript.Shell")
MsgBox "Your desktop is " & WshShell.SpecialFolders("Desktop")

End Sub
Ed - 10 May 2006 16:35 GMT
Never mind!  I should have Googled the NG ~before~ posting!!  As usual, the
experts have resolved this already, and I am behind the curve!
Ed

> I'm attempting to use Wscript.Shell through Word 2002 VBA to access a
> shortcut's TargetPath.  Actually, right now I'm just attempting to set an
[quoted text clipped - 13 lines]
>
> End Sub
Helmut Weber - 10 May 2006 16:38 GMT
Hi Ed,

>Set WshShell = Wscript.CreateObject("Wscript.Shell") ' ???

Sub GetDesktop()
Dim WshShell As Object
Set WshShell = CreateObject("Wscript.Shell")
MsgBox "Your desktop is " & WshShell.SpecialFolders("Desktop")
Set WshShell = Nothing
End Sub

Dim WshShell As Object <<<

is some kind of a compromise,
as I could find the right type in the intellisense.
Maybe there isn't one at all.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Ed - 10 May 2006 19:01 GMT
Hi, Helmut.  I was scanning lots of programming web sites to come up with
what I originally posted.  I think I might have been trying to use something
other than VBA in my macro!  Using some hints I found in a Word.VBA NG post,
I put together the following.  It works for me in Windows XP with Word 2002.
Ed

Sub TryAgain2()

Dim strName As String
' Requires a reference to Windows Script Host Object Model
Dim objShell As IWshRuntimeLibrary.WshShell
Dim objLink As WshShortcut
' Requires a reference to Microsoft Scripting Runtime Library
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

' Get UserName
UName = Environ$("Username")
' Set folder path
MyPath = "C:\Documents and Settings\" & _
   UName & "\Recent\"

' Get files
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(MyPath)
If Not objFolder Is Nothing Then
   For Each objFile In objFolder.Files
       With objFile
         strName = objFile.Name

       Set objShell = New IWshRuntimeLibrary.WshShell
       Set objLink = objShell.CreateShortcut(MyPath & strName)
       Debug.Print objLink.TargetPath

       End With
   Next objFile
End If

Set objLink = Nothing
Set objShell = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing

End Sub

> Hi Ed,
>
[quoted text clipped - 12 lines]
> as I could find the right type in the intellisense.
> Maybe there isn't one at all.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.