Submitted By: Kent Finkle

Adds a hyperlink to a Microsoft Excel spreadsheet.

PowerShell
Edit|Remove
$comments = @'
Script name: Add-ExcelHyperlink.ps1
Created on: Wednesday, July 11, 2007
Author: Kent Finkle
Purpose: How can I use Windows Powershell to
Add a Hyperlink to an Excel Spreadsheet?
'@
#-----------------------------------------------------
function Release-Ref ($info) {
    foreach ( $p in $args ) { 
        ([System.Runtime.InteropServices.Marshal]::ReleaseComObject(
        [System.__ComObject]$p) -gt 0)
        [System.GC]::Collect()
        [System.GC]::WaitForPendingFinalizers() 
    }    
}
#-----------------------------------------------------
$link = "http://www.microsoft.com/technet/scriptcenter"
 
$xl = new-object -comobject excel.application
$xl.Visible = $True
 
$wb = $xl.Workbooks.Add()

$ws = $wb.Worksheets.Item(1)
 
$ws.Cells.Item(1, 1).Value() = "Script Center"
 
$r = $ws.Range("A1")

$objLink = $ws.Hyperlinks.Add($r, $link)
 
$a = Release-Ref $r $ws $wb $xl