How to send shortcut to desktop after saving in My Docs?

P

Paul

I have found that even though I like to save files to the My Documents
folder, I like to put shortcuts on the desktop to those that I know I'll be
coming back to in the next few weeks, even though they might slip out of the
File>Recent Documents menu at the bottom. However, I'm always wondering when
I save to these folders within folders within My Docs, if there isn't an
easier way to get a shortcut onto the desktop, than drill down later on and
then right-click>Send to>Desktop. Is there a way, when the document has
already been saved, when you are still working on a document, to get a
shortcut to it placed onto the desktop? It would save me from that drill
down.
--
Paul

MS Office Pro 2003
XP Home SP3
Dell Inspiron 1501
 
J

Jay Freedman

I have found that even though I like to save files to the My Documents
folder, I like to put shortcuts on the desktop to those that I know I'll be
coming back to in the next few weeks, even though they might slip out of the
File>Recent Documents menu at the bottom. However, I'm always wondering when
I save to these folders within folders within My Docs, if there isn't an
easier way to get a shortcut onto the desktop, than drill down later on and
then right-click>Send to>Desktop. Is there a way, when the document has
already been saved, when you are still working on a document, to get a
shortcut to it placed onto the desktop? It would save me from that drill
down.

Add this macro to your Normal.dot template (see
http://www.gmayor.com/installing_macro.htm if needed). In the VBA editor, you'll
have to go to Tools > References and put a check mark in the box next to
"Windows Script Host Object Model" to make the macro work.

Sub MakeShortcut()
' Create a desktop shortcut to the active document.
' Note: this macro requires a reference to
' the Windows Script Host Object Model (wshom.ocx)

' If the document hasn't been saved yet,
' warn and exit
If Len(ActiveDocument.Path) = 0 Then
MsgBox "You must save the document first."
Exit Sub
End If

Dim oShell As WshShell
Dim sDesktopPath As String
Dim sLinkPath As String
Dim oShortcut As WshShortcut

Set oShell = New WshShell
' Get the path to the user's desktop
sDesktopPath = oShell.SpecialFolders("Desktop")
' Build the filename for the link file
sLinkPath = sDesktopPath & "\" & _
ActiveDocument.Name & ".lnk"
' Create the link file
Set oShortcut = oShell.CreateShortcut(sLinkPath)
' Assign the link's target to the active document
With oShortcut
.TargetPath = ActiveDocument.FullName
.Save
End With

' Clean up
Set oShortcut = Nothing
Set oShell = Nothing
End Sub

Create a toolbar button or keyboard shortcut to run the macro.
 
P

Paul

Thanks, Jay. The gmayor site was down so I went to the Word MVPS site and
found an article here:
http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

However, after copying and pasting your code, and following the directions
above, I got the following error whenever I try to run the keyboaard shortcut
(Ctrl+D+S):

Compile Error: User-defined type not defined.

It brings up the macro script, but that is all.

Suggestions?
--
Paul

MS Office Pro 2003
XP Home SP3
Dell Inspiron 1501
 
P

Paul

In case I didn't clarify in the above post, in addition to the error message
the desktop shortcut is not created. BTW--using Ctrl in my shortcut doesn't
work (Brings up font options) so I had to change it to Alt+D+S.
--
Paul

MS Office Pro 2003
XP Home SP3
Dell Inspiron 1501
 
J

Jay Freedman

I think you overlooked this instruction in my original post:

Because that reference is missing, VBA doesn't recognize the words "WshShell"
and "WshShortcut" as valid data types.
 
P

Paul

Thanks, Jay. OK its working now b/c I went back and put that check mark in.

After forums, I'm still not used to this software...I didn't see your reply
till just now. Oh well all's well that ends well.
--
Paul

MS Office Pro 2003
XP Home SP3
Dell Inspiron 1501
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top