Tommy Alatalo
New Member
- Joined
- Feb 12, 2017
- Messages
- 28
I am creating a VBA script that loops through all .lnk (shortcuts) files in a folder, and inserts the filenames to a spreadsheet.
The problem I'm having with this is that once I create the shortcuts in Windows the shortcuts don't seem to update if I change the filename of the file that the shortcut points to.
Example of the behavior:
Step 1:
[folder with shortcuts]\ShortcutToFileA.lnk
[folder containing file]\FileA.pdf
Excel VBA inserts "FileA.pdf"
Step 2 (filename changes):
[folder with shortcuts]\ShortcutToFileA.lnk
[folder containing file]\FileA_Plus.pdf (renamed FileA.pdf)
Excel VBA still inserts "FileA.pdf"
So ShortcutToFileA.lnk still says "FileA" when getting the targetPath after renaming the file.
My Code:
Is there a way to update or resolve the shortcut created in Windows explorer so that the VBA script gets the correct filename information every time even when the target filename changes?
The shortcut in windows explorer still points to the file "FileA_Plus.pdf" and opens correctly with Adobe Reader if I just change the name of that file, but for some reason the WScript shortcut doesn't see this change.
Help much appreciated!
The problem I'm having with this is that once I create the shortcuts in Windows the shortcuts don't seem to update if I change the filename of the file that the shortcut points to.
Example of the behavior:
Step 1:
[folder with shortcuts]\ShortcutToFileA.lnk
[folder containing file]\FileA.pdf
Excel VBA inserts "FileA.pdf"
Step 2 (filename changes):
[folder with shortcuts]\ShortcutToFileA.lnk
[folder containing file]\FileA_Plus.pdf (renamed FileA.pdf)
Excel VBA still inserts "FileA.pdf"
So ShortcutToFileA.lnk still says "FileA" when getting the targetPath after renaming the file.
My Code:
Code:
For Each File In Folder.Files
Dim WSHShell As Object
Dim shortcut As Object
Set WSHShell = CreateObject("WScript.Shell")
With WSHShell.CreateShortcut(FileSystem.GetAbsolutePathName(File))
linkPath = .TargetPath
End With
**Use wordarray to get relevant sections of the filename to my spreadsheet**
Next
Is there a way to update or resolve the shortcut created in Windows explorer so that the VBA script gets the correct filename information every time even when the target filename changes?
The shortcut in windows explorer still points to the file "FileA_Plus.pdf" and opens correctly with Adobe Reader if I just change the name of that file, but for some reason the WScript shortcut doesn't see this change.
Help much appreciated!