Add-Type -AssemblyName Microsoft.Office.Interop.Excel
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.Add()
$worksheet = $workbook.Worksheets.Item(1)
$currentRow = 1
$currentColumn = 1
while ($true) {
Write-Host "Press ESC to stop..."
if ([System.Console]::KeyAvailable -and ([System.Console]::ReadKey($true).Key -eq [System.ConsoleKey]::Escape)) {
break
}
$image = Get-Clipboard -Format Image
$tempImagePath = "C:\Path\To\Your\Temp\Image.png"
$image.Save($tempImagePath)
$worksheet.Shapes.AddPicture($tempImagePath, $false, $true, $range.Left, $range.Top, -1, -1)
$currentRow++
$workbook.SaveAs("C:\Path\To\Your\Excel\File.xlsx")
Remove-Item $tempImagePath
Start-Sleep -Seconds 5
}
$workbook.Close($false)
$excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)