เปลี่ยน icon Shortcut บน Dasktop
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 312   3
URL.หัวข้อ / URL
เปลี่ยน icon Shortcut บน Dasktop

เรียนถาม อ.สุภาพ และท่านผู้รู้ครับ
ผมมีคำถาม ซึ่งไม่ทราบว่า จะมีทางเป็นไปได้หรือไม่
มีวิธีไหนบ้างครับที่เราสามารถ เปลี่ยน icon Shortcut บน Dasktop แบบอัตโนมัติ
โดยเรากำหนด path ของ icon และ ชื่อของ icon ไว้ก่อน จากนั้นเราสร้างปุ่มขึ้นมาแล้วเขียนโค้ดให้เปลี่ยนแปลงรูป icon Shortcut บน Dasktop ทันที โดยที่เราไม่ต้องคลิกขวาเลือก คุณสมบัติ ของShortcut เพื่อทำการเปลี่ยน icon
ไม่ทราบว่ามีทางจะเป็นไปได้หรือไม่ครับ
ช่วยแนะนำด้วยครับผม ขอบคุณครับ

3 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06456
ลองค้นหาด้วยคำว่า Shortcut ดูครับ
2 @R06462
Function fCreateShortcutOnDesktop(strFullFilePathName As String) _
As Long

Dim WSHShell As Object
Dim WSHShortcut As Object
Dim strDesktopPath As String
Dim strFileName As String

Dim strPath As String
On Error GoTo fCreateShortcutOnDesktop_Err
' Create a Windows Shell Object
Set WSHShell = CreateObject("WScript.Shell") 'New IWshRuntimeLibrary.IWshShell_Class
' Get the file's name and path...
strFileName = Dir(strFullFilePathName)
strPath = Left(strFullFilePathName, _
Len(strFullFilePathName) - Len(strFileName))

' Make sure file exists
If Not Len(strFileName) = 0 Then

' Read desktop path using WshSpecialFolders object
strDesktopPath = WSHShell.SpecialFolders.Item("Desktop")

' Create a shortcut object on the desktop
Set WSHShortcut = WSHShell.CreateShortcut _
(strDesktopPath & "\" & strFileName & ".lnk")

' Set shortcut object properties and save it
With WSHShortcut
.TargetPath = WSHShell. _
ExpandEnvironmentStrings(strFullFilePathName)
.WorkingDirectory = WSHShell. _
ExpandEnvironmentStrings(strPath)
.WindowStyle = 4
.IconLocation = WSHShell.ExpandEnvironmentStrings(SysCmd(acSysCmdAccessDir) _
& "\msaccess.exe ,0") 'I get hung on this line and the msaccess.exe use to be excel.exe
.Save
End With

fCreateShortcutOnDesktop = 1
Else
fCreateShortcutOnDesktop = 0
End If
Continue:
' Tidy Up
Set WSHShell = Nothing
Exit Function

fCreateShortcutOnDesktop_Err:
fCreateShortcutOnDesktop = -1
Resume Continue

End Function
+++++++++++++++++++++++++++++++++
จากโค้ดที่ได้มา ไม่ทราบว่าเวลานำไปใช้ จะต้องทำอย่างไรครับ
ผมใช้ win xp MS Access xp
รบกวนอีกครั้งครับ
3 @R06464
ก็เรียกฟังก์ชัน โดยใส่ชื่อไฟล์ mdb ที่ต้องการลงไป พร้อมกับ Path ด้วยครับ

เช่น จะสร้าง Shortcut ให้ไฟล์ปัจจุบันที่เปิดอยู่ ก็ใช้

fCreateShortcutOnDesktop(CurrentDb.Name)

ขึ้นอยู่กับว่าจะเรียกฟังก์ชันนี้ตอนไหน ก็นำไปใช้ได้เลยครับ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0518s