Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell - Searching Excel and replacing text

$
0
0

Hi all,

I am trying to figure out how to loop this script so that it replaces all the text that I am searching for in my Excel file.  I am able to get it to run but it only replaces the text in the first column and then ends. Any help is appreciated and thanks in advance.

-Gaz

$File="D:\test.xlsx"

# Setup Excel, open $File and set the the first worksheet
$Excel=New-Object-ComObjectExcel.Application
$Excel.visible=$true
$Workbook=$Excel.workbooks.open($file)
$Worksheets=$Workbooks.worksheets
$Worksheet=$Workbook.Worksheets.Item(1)

$SearchString="TEMP# This is the value that I will be searching for

$Range=$Worksheet.Range("A1").EntireColumn
$Search=$Range.find($SearchString)

$Search.value()="ABSENT"# This is the value that i want to replace the text with.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>