Robby
Robby

Reputation: 827

Delete file within APPDATA folder

I have many PCs that currently have a Personal macro workbook installed. More specifically, they all have a shortcut to a Personal macro workbook on a network drive.

To install that, I went to each PC and ran this VBScript:

Option Explicit
Dim oFSO, strAppData, objShell
Set objShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
objShell.CurrentDirectory = oFSO.GetParentFolderName(WScript.ScriptFullName)
strAppData=objShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Excel\XLSTART\"
oFSO.CopyFile "H:\Folder\Folder\Folder\PERSONAL 1.xlam - Shortcut.lnk", strAppData, True
Set objShell = Nothing
Set oFSO = Nothing

Now though, I want to remove that shortcut to PERSONAL 1.xlam from the XLSTART folder and copy over a shortcut to a different macro workbook.

This might be really easy, but I'm new to VBS and I haven't found a way to delete a file without having the the exact path. And since the path is going to be unique to each PC, I can't do that here.

Upvotes: 0

Views: 1411

Answers (1)

Brian M Stafford
Brian M Stafford

Reputation: 8868

You just need to modify one line from the above script. Try the following:

   Option Explicit
   Dim oFSO, strAppData, objShell
   Set objShell = CreateObject("WScript.Shell")
   Set oFSO = CreateObject("Scripting.FileSystemObject")
   objShell.CurrentDirectory = oFSO.GetParentFolderName(WScript.ScriptFullName)
   strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Excel\XLSTART\"

   'here is the modified line
   oFSO.DeleteFile strAppData & "PERSONAL 1.xlam - Shortcut.lnk", True

   Set objShell = Nothing
   Set oFSO = Nothing

Upvotes: 1

Related Questions