Howard
Sat Jul 03 13:02:46 CDT 2004
I suspect you are using Word 97.
You need word 2000, or later, for Instrrev.
--
http://www.standards.com/; See Howard Kaikow's web site.
"Larry" <larry328@att.net> wrote in message
news:emT3ryRYEHA.3568@TK2MSFTNGP10.phx.gbl...
>
>
> Hi Peter,
>
> Thanks for this.
>
> As you told me, I checked the Windows Script Host Object Model under
> Tools, References. But when I try to run the macro, I get a message
> saying "sub or function not defined" and InStrRev is highlighted in the
> below line:
>
> lngPos = InStrRev(ActiveDocument.Name, ".")
>
> InStrRev is not mentioned in VB Help, so I experimented with changing it
> to
>
> lngPos = InStr(ActiveDocument.Name, ".")
>
> Now when I run the macro, I get a run-time error, and when I click on
> Debug, the below line is highlighted:
>
> objLink.Save
>
> If we could get this working it would be great. It would be a more
> powerful substitute for the Work menu. I found a couple of articles on
> the web about creating a shortcut through vba, but they were were
> written for programmers and too complicated for me to understand.
>
> Larry
>
>
>
> "Peter Hewett" <nospam@xtra.co.nz> wrote in message
> news:2p3de0lpk3avri3h4heumdu61hpm2qsrka@4ax.com...
> > Hi Larry
> >
> > It seems you have all the pieces of your puzzle already. Here's a
> modified version of the
> > code that will create a shortcut to the ActiveDocument (it it's been
> saved):
> >
> > Public Sub CreateShortCut()
> > ' Requires a project reference to "Windows Script Host Object
> Model"
> > Dim shl As IWshRuntimeLibrary.WshShell
> > Dim objLink As Object
> > Dim lngPos As Long
> > Dim strDestination As String
> > Dim strPackageName As String
> >
> > ' If the current documents not been saved then we can't create a
> shortcut
> > If LenB(ActiveDocument.Path) = 0 Then Exit Sub
> >
> > ' Path for link file
> > strDestination = "C:\Temp\"
> >
> > ' Just want the name part (no file type)
> > lngPos = InStrRev(ActiveDocument.Name, ".")
> > If lngPos > 0 Then
> > strPackageName = Left$(ActiveDocument.Name, lngPos - 1)
> > End If
> >
> > ' Create the shortcut to the current document
> > Set shl = New IWshRuntimeLibrary.WshShell
> > Set objLink = shl.CreateShortCut(strDestination & strPackageName &
> ".lnk")
> > objLink.TargetPath = (ActiveDocument.FullName)
> > objLink.Save
> >
> > Set objLink = Nothing
> > Set shl = Nothing
> > End Sub
> >
> > To delete the shortcut, just delete the link file:
> > Dim strDestination As String
> > Dim strPackageName As String
> >
> > ' Just want the name part (no file type)
> > lngPos = InStrRev(ActiveDocument.Name, ".")
> > If lngPos > 0 Then
> > strPackageName = Left$(ActiveDocument.Name, lngPos - 1)
> > End If
> > Kill "C\Temp\" & strPackageName & ".lnk"
> >
> > HTH + Cheers - Peter
> >
> >
> > "Larry" <larry328@att.net>, said:
> >
> > >
> > >
> > >
> > >This is really a vba question yet I neglected initially to send it to
> > >the vba group.. I've cancelled the original messages, which had some
> > >mistakes, and I'm starting over.
> > >
> > >Is there a command that I could run through VBA that would create a
> > >shortcut to the active Word document and place that shortcut in a
> > >particular folder? Let's say the folder is: C:\Documents\Work
> > >
> > >The manual equivalent of this, which I already have, is to add to the
> > >Windows/SendTo folder a shortcut to a .vbs file which sends a
> shortcut
> > >of the document to the folder. But I want to automate this from
> within
> > >Word.
> > >
> > >Here is the code of the .vbs file. A shortcut to this .vbs file is
> in
> > >my Windows\SendTo folder. :
> > >
> > >Dim fso, Package, PkgName, Destination, link, Top, I
> > >
> > >Destination = "C:\Documents\Work"
> > >
> > >Set shell = CreateObject("WScript.Shell")
> > >Set fso = CreateObject("Scripting.FileSystemObject")
> > >Top = WScript.Arguments.Count
> > >For I = 0 To (Top-1)
> > >Package = WScript.Arguments.Item(I)
> > >PkgName=fso.GetBaseName(Package)
> > >Set link = shell.CreateShortcut(Destination&"\"&PkgName&".lnk")
> > > link.TargetPath = (Package)
> > > link.Save
> > >Next
> > >' MsgBox "Shortcuts to the file(s) or folder(s) are being created
> > >at:"&vbCRLF&Destination
> > >Set shell = Nothing
> > >Set fso = Nothing
> > >
> > >Also, in addition to placing a shortcut in the folder, would there be
> a
> > >command I could run through VBA that would delete the shortcut of the
> > >active document from the C:\Documents\Work folder?
> > >
> > >I'm basically trying to come up with a more powerful equivalent of
> > >Word's Work
> > >menu.
> > >
> > >I'm working with Word 97, on Windows 98.
> > >
> > >Thanks,
> > >Larry
> > >
> > >
> > >
> >
>
>