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  
PowerShell script to open target worksheet in target workbook


Bookmark and Share

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

In my previous post, I wrote a script to open an excel workbook, now I extend that function a little bid to open your target worksheet in excel workbook.

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")

function global:Open-Worksheet()
{
param($excel, [string]$excelfilename, [string]$worksheetname)
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
}
$worksheet = $($excel.Workbooks.Open($excelfilename)).Worksheets.Item($WorksheetName)

}
Open-Worksheet $excel $excelfilename $worksheetname



  myITforum.com ©2010 | Legal | Privacy