Mình có 1 file quản lý lệnh hang.xls và 1 file tạo shortcut trên file dektop cho file này, để tạo shortcut auto cho file quản lý lệnh hang.xls, file tạo shortcut phải cùng thư mục. Chủ đề của bạn muốn tạo shortcut tạo file trên desktop và click vào nó, nó vẫn tạo file shortcut cho file Quan ly ban hang.xls trên màn hình desktop Cả icon luôn nhé!
em muốn tạo shortcut tự động cho file bao gồm cả icon luôn ah"Tôi muốn tạo shortcut cho một file trên màn hình Desktop" <---- Ý là vậy đúng không?
Viết lằng nhằng, đọc không hiểu gì ráo!
Code tạo shortcut:em muốn tạo shortcut tự động cho file bao gồm cả icon luôn ah
Private Sub CreateShortcut(ByVal SourceFile As String, ByVal IconFile As String, _
ByVal ShortcutPlace As String, ByVal ShortcutName As String)
On Error Resume Next
If Right(ShortcutPlace, 1) <> "\" Then ShortcutPlace = ShortcutPlace & "\"
With CreateObject("WScript.Shell")
With .CreateShortCut(ShortcutPlace & ShortcutName & ".lnk")
.TargetPath = SourceFile
.IconLocation = IconFile
.Save
End With
End With
End Sub
Sub Main()
Dim SourceFile As String, IconFile As String, ShortcutPlace As String, ShortcutName As String
SourceFile = "Đường dẫn file nguồn"
IconFile = "Đường dẫn file icon
ShortcutPlace = CreateObject("WScript.Shell").SpecialFolders("Desktop") ''<-- đây là thư mục desktop
ShortcutName = "Tên shortcut"
CreateShortcut SourceFile, IconFile, ShortcutPlace, ShortcutName
End Sub
Thì thêm đường dẫn file của bạn vào thôiThầy giúp em code file này ah
Dim SourceFile As String, IconFile As String, ShortcutPlace As String, ShortcutName As String
SourceFile = ThisWorkbook.FullName
IconFile = "C:\WINDOWS\system32\shell32.dll, 14"
ShortcutPlace = CreateObject("WScript.Shell").SpecialFolders("Desktop") ''<-- dây là thu m?c desktop
ShortcutName = "Tào lao"
CreateShortcut SourceFile, IconFile, ShortcutPlace, ShortcutName
End Sub