Grab our RSS feeds Follow us on Twitter Join our Facebook Group Connect with us on LinkedIn
myITforum.com, Powered by You.
you are not logged in

Articles

Newslinks

Links

Downloads

Site Services

Community Forums

Discussion Lists

Article Search

Newsletter

Web Blogs

FAQs

Live Support

myITforum TV

Take a Poll

Monthly Drawing

myITforum Network

User Group Directory

Our Partners

About Us

Register

Login

BRONZE PARTNER:

BRONZE PARTNER:



Industry News:




  Home : Articles : Windows PowerShell print | email | | Forums |   print | email | | Blogs |   print | email | | Wiki |   print | email | | FAQs |   print | email | Article Search  
One step further - to open a working range in excel worksheet


Bookmark and Share

By: Ying Li
Posted On: 5/22/2007

Here I will extend a little bid further from my two previous posts and to open a working range inside the target worksheet.

This article was Previously posted on Ying Li's Blog

################################################################################

$excel = new-object -comobject Excel.Application
$excel.visible = $True

# Inputbox
$x = new-object -comobject MSScriptControl.ScriptControl
$x.language = "vbscript"
$x.addcode("function getInput() getInput = inputbox(`"Enter the full path of your excel file`",`"Workbook Name`") end function" )
$excelfilename = $x.eval("getInput")

$x = new-object -comobject MSScriptControl.ScriptControl
$x.language = "vbscript"
$x.addcode("function getInput() getInput = inputbox(`"Enter the worksheet name`",`"WorkSheet Name`") end function" )
$worksheetname = $x.eval("getInput")

$x = new-object -comobject MSScriptControl.ScriptControl
$x.language = "vbscript"
$x.addcode("function getInput() getInput = inputbox(`"Enter the Range name`",`"Working Range Name`") end function" )
$rangename = $x.eval("getInput")

function global:Open-Range()
{
param($excel, [string]$excelfilename, [string]$worksheetname,[string]$rangename)
if (!$(test-path $excelfilename))
{
write-host "File doesn't exist..."
return $null
}
if ([string]::IsNullOrEmpty($worksheetName))
{
write-host "Worksheet name cannot be null or empty."
return $null
}
if ([string]::IsNullOrEmpty($rangeName))
{
write-host "Range name cannot be null or empty."
return $null
}
$worksheet = $($excel.Workbooks.Open($excelfilename)).Worksheets.Item($worksheetName)
$range = $worksheet.Range($RangeName)
}

Open-Range $excel $excelfilename $worksheetname $rangename



#################################################################################

Now we have the target range open, we could manipulate the data, create an array out of certain column, do some comparision, update the open excel sheet and save the results - to be continued…


  myITforum.com ©2010 | Legal | Privacy