Avatar of Flora Edwards
Flora EdwardsFlag for Sweden

asked on 

can this macro be converted to sub procedure

i got this code referred by aikimark from https://gallery.technet.microsoft.com/scriptcenter/191eb207-3a7e-4dbc-884d-5f4498440574

now i want to use this as sub procedure

so that instead of strFileToToss = "C:\Test\trash.txt"

i can use   strFileToToss("C:\Test\trash.txt")

strFileToToss = "C:\Test\trash.txt" 
 
 
Const HKEY_CURRENT_USER = &H80000001 
strComputer = "." 
 
Set fso = CreateObject("Scripting.FileSystemObject") 
 
If Not fso.FileExists(strFileToToss) Then 
   WScript.Quit 
End If 
 
If fso.GetExtensionName(strFileToToss) = "exe" Then 
   WScript.Quit 
End If 
 
strFolderParent = fso.GetParentFolderName(strFileToToss) 
strFileName = fso.GetFileName(strFileToToss) 
 
 
'   Make sure recycle bin properties are set to NOT display request for delete confirmation 
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _  
    strComputer & "\root\default:StdRegProv") 
  
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer" 
strValueName = "ShellState" 
 
oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath, _ 
    strValueName,strValue 
 
strOrigBinSet = strValue(4) 
strValue(4) = 39 
 
errReturnA = oReg.SetBinaryValue _ 
   (HKEY_CURRENT_USER, strKeyPath, strValueName, strValue) 
 
 
'  Use the Shell to send the file to the recycle bin 
 
Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.Namespace(strFolderParent) 
Set objFolderItem = objFolder.ParseName(strFileName) 
 
objFolderItem.InvokeVerb("&Delete") 
 
 
'  Restore the User's Property settings for the Recycle Bin 
 
strValue(4) = strOrigBinSet 
errReturnB = oReg.SetBinaryValue _ 
   (HKEY_CURRENT_USER, strKeyPath, strValueName, strValue

Open in new window

VB ScriptVBAVisual Basic Classic

Avatar of undefined
Last Comment
Flora Edwards
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Flora Edwards
Flora Edwards
Flag of Sweden image

ASKER

i saw a post from Bill but then it disappeared.
Avatar of Bill Prew
Bill Prew

It's back, sorry, posted before I finished testing...

~bp
Avatar of Flora Edwards
Flora Edwards
Flag of Sweden image

ASKER

Thanks so very much Bill.

it worked perfectly.
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo