อยากสร้างช๊อตคัทไว้บน desktop ต้องเขียนโค้ดอย่างไร
https://www.thai-access.com/suphap.php?topic_id=1236
(ใช้บอร์ด smf 2.0.15 สวยดี)
ผมขออนุญาติถามคำถามต่อนะครับ แล้วเราจะนำ Short Cut ที่สร้างขึ้น Send to Desktop ได้อย่างไร
โดยการใช้ Code พร้อมทั้งกำหนดรูปภาพของ Short Cut ด้วยครับ ขอบพระคุณมากครับ
ผมได้ลองไปทดสอบการใช้งานจริงปรากฎว่าสามารถไปสร้างบน Desktop ได้จริงๆ หลักการก็คือ ใช้ Code ตามที่อาจารย์แนะนำ ก็จะสามารถสร้าง ShortCut ขึ้นมาได้ตามตำแหน่งที่เราระบุตาม Code ด้านบน จากนั้นใช้คำสั่ง Name......as........ เพื่อนำ ShortCut นั้นไปเก็บที่ Folder Desktop ของ Windows ซึ่งแต่ละ OS จะอยู่ไม่เหมือนกัน เช่น Windows98 มักสร้างไว้ที่ C:\windows\Desktop เป็นต้น เพียงเท่านี้ ShortCut ก็จะไปปรากฎบนหน้าจอ Windows ครับ
เปลี่ยน icon Shortcut บน Dasktop
เรียนถาม อ.สุภาพ และท่านผู้รู้ครับ
ผมมีคำถาม ซึ่งไม่ทราบว่า จะมีทางเป็นไปได้หรือไม่
มีวิธีไหนบ้างครับที่เราสามารถ เปลี่ยน icon Shortcut บน Dasktop แบบอัตโนมัติ
โดยเรากำหนด path ของ icon และ ชื่อของ icon ไว้ก่อน จากนั้นเราสร้างปุ่มขึ้นมาแล้วเขียนโค้ดให้เปลี่ยนแปลงรูป
icon Shortcut บน Dasktop ทันที โดยที่เราไม่ต้องคลิกขวาเลือก คุณสมบัติ ของShortcut เพื่อทำการเปลี่ยน icon
ไม่ทราบว่ามีทางจะเป็นไปได้หรือไม่ครับ
ช่วยแนะนำด้วยครับผม ขอบคุณครับ
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
รบกวนอีกครั้งครับ
ก็เรียกฟังก์ชัน โดยใส่ชื่อไฟล์ mdb ที่ต้องการลงไป พร้อมกับ Path ด้วยครับ
เช่น จะสร้าง Shortcut ให้ไฟล์ปัจจุบันที่เปิดอยู่ ก็ใช้
fCreateShortcutOnDesktop(CurrentDb.Name)
ขึ้นอยู่กับว่าจะเรียกฟังก์ชันนี้ตอนไหน ก็นำไปใช้ได้เลยครับ