Visual Basic para Aplicaciones - Crear Shortcut de folder desde VBA

Life is soft - evento anual de software empresarial
 
Vista:

Crear Shortcut de folder desde VBA

Publicado por Alejadro (3 intervenciones) el 30/07/2007 14:42:15
Buenas Tardes,

Necesito crear desde VBA una función que permita en tiempo de ejecución crear un acceso directo de una carpeta en una ubicación específica.

Alguien me podria ayudar con este tema

Muchas gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Crear Shortcut de folder desde VBA

Publicado por JuanC (243 intervenciones) el 30/07/2007 21:28:38
' Author: Perikov Vadim
'«Microsoft Shell Controls And Automation» (????? Shell32.dll)

Option Explicit
Private Declare Function lcreat Lib "kernel32" Alias "_lcreat" (ByVal lpPathName As String, ByVal iAttribute As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const Delim = "\"

Public Function CreateShortcut(ByVal fCreateFileLnk As String, ByVal fFileObject As String, Optional ByVal fArguments As String = "", Optional ByVal fWorkingDir As String = "", Optional ByVal fDescription As String = "", Optional ByVal fShowCommand As Long = 1, Optional ByVal fFileIcon As String = "", Optional ByVal fIconNumber As Long = 0, Optional ByVal fHotkey As Long = 0) As Long
Dim fsHwnd As Long
Dim fsDl As Long

Dim csShell As Shell
Dim csFolder As Folder
Dim csItem As FolderItem

Dim fsLink As ShellLinkObject

On Error GoTo Errors

fsHwnd = lcreat(fCreateFileLnk, 0)
fsDl = CloseHandle(fsHwnd)

Set csShell = New Shell

Set csFolder = csShell.NameSpace(Left$(fCreateFileLnk, InStrRev(fCreateFileLnk, Delim, , 1) - 1))
Set csItem = csFolder.ParseName(Mid$(fCreateFileLnk, InStrRev(fCreateFileLnk, Delim, , 1) + 1))
If csItem.IsLink = True Then
Set fsLink = csItem.GetLink
End If

fsLink.Path = fFileObject
fsLink.Arguments = fArguments
fsLink.WorkingDirectory = fWorkingDir
fsLink.Description = fDescription
fsLink.ShowCommand = fShowCommand
' Hotkey
'512 - <Ctrl>
'1024 - <Alt>
'512+1024 - <Ctrl+Alt>
If fHotkey > 0 And fHotkey < 256 Then fsLink.HotKey = 512 + 1024 + fHotkey

fsLink.SetIconLocation fFileIcon, fIconNumber

fsLink.Save

If Not (fsLink Is Nothing) Then Set fsLink = Nothing
If Not (csItem Is Nothing) Then Set csItem = Nothing
If Not (csFolder Is Nothing) Then Set csFolder = Nothing
If Not (csShell Is Nothing) Then Set csShell = Nothing
CreateShortcut = 1
Exit Function
Errors:
CreateShortcut = 0
End Function

Sub test()
CreateShortcut "c:\windows\escritorio\Acceso Directo a pp.lnk", "c:\windows\escritorio\pp\"
End Sub

Saludos desde Baires, JuanC
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Crear Shortcut de folder desde VBA

Publicado por Alejandro (3 intervenciones) el 31/07/2007 06:55:06
Juan C, muchas gracias por la respuesta, funciona bastante bien
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Crear Shortcut de archivo desde VBA

Publicado por Alejandro (3 intervenciones) el 26/11/2007 12:49:34
Buenas Tardes

Alguien sabe como crear una acceso directo en tiempo de ejecución sobre VBA para excel, el codigo del correo adjunto lo realiza para un folder pero genera errores para archivos.

Muchas gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:Crear Shortcut de folder desde VBA

Publicado por Javier Reinoso (1 intervención) el 25/07/2009 12:30:57
Si se desea crear un link al archivo, pero que se abra una ventana nueva de explorer a ese archivo, es asi:

'Añadir Referencia a Microsoft Scripting Runtime (scrrun.dll)

Public Function CreateShortcutExplorerToArchiveInNewWindow(ArchiveToLink As String, ShortCutSaveInPath As String, Winstyle As FormWindowStateConstants)
Dim objWshShell As Object
Dim ShortCut As Object

Set objWshShell = CreateObject("Wscript.shell")
Set ShortCut = objWshShell.CreateShortcut(ShortCutSaveInPath)

ShortCut.TargetPath = "%windir%explorer.exe"
ShortCut.Arguments = " /n,/e,/select, " + ArchiveToLink
ShortCut.WindowStyle = Winstyle

ShortCut.Save
End Function

Sub test()
CreateShortcutExplorerToArchiveInNewWindow "c:oot.ini", "c: est.lnk", vbNormal
end sub

Esto abre el explorer en uan ventana nueva con el archivo seleccionado...

Saludos!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar