Hi @MrFlinstone ,
Does this work for you?
Add-Type -AssemblyName Microsoft.Office.Interop.Excel
$Excel = New-Object -ComObject Excel.Application
$FilePath = 'C:\output\file.xlsm'
$TemplatePath = 'C:\output\template.xlsm'
$FileBook = $Excel.workbooks.Open($filepath)
$FileSheet = $FileBook.Worksheets.item(1)
$FileColumns = $filesheet.UsedRange.Columns.Count
$FileHeaders = @()
for($i=1;$i -le $FileColumns;$i++){
$FileHeaders += $FileSheet.UsedRange.Cells.Item(1,$i).Text
}
$FileBook.Close()
$Excel.Visible = $true
$TemplateBook = $Excel.workbooks.Open($TemplatePath)
$TemplateSheet = $TemplateBook.Worksheets.Item(1)
$TemplateColumns = $TemplateSheet.UsedRange.Columns.Count
for($j=1;$j -le $TemplateColumns;$j++){
if($TemplateSheet.Cells.Item(1,$j).text -notin $FileHeaders){
$TemplateSheet.Cells.Item(1,$j).interior.colorindex = 3
}
}
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.