header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Excel questions...
Last Post 25 Sep 2008 12:00 PM by Shay. 6 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
jason_stephensUser is Offline
New Member
New Member
Posts:15
Avatar

--
12 Sep 2008 08:19 PM  

I was wanting to use the active cell type of reference. Kind of like using the active cell as a cursor. Most of the examples on the web are accessing cells and sheets with their coordinates. How would I select a particular sheet as the active sheet using it's name and then how would I select a particular cell as the active cell? I am wanting to update a daily log that has two named sheets with stuff in the log. I want to append to the next line of each sheet using stuff like "$objExcel.ActiveCell.Value2 =" and "$objWorkbook.ActiveSheet.Cells.SpecialCells(11).Activate". I found some code but I don't think it works for powershell..."$objWorkbook.worksheets.item("AAMCHTM2").Activate". The above is my main question. My second is how to be able to actually look up how to do this using the get-help and get-member commands. I can kind of make it work, but it gets tricky once I have my excel object exactly how to find the proper syntax and usage of the methods and parameters. Anyone know of a good tutorial that actually walks you through finding something like "how to troubleshoot and find the proper syntax for finding how to rename a sheet in excel"? Using these tools to figure it out myself will get me a lot farther than I am now. Thanks. P.S. What is the deal with that "2" at the end of "$objExcel.ActiveCell.Value2 ="

Thanks.

P.S. What is the deal with that "2" at the end of "$objExcel.ActiveCell.Value2 ="

ShayUser is Online
Basic Member
Basic Member
Posts:281
Avatar

--
14 Sep 2008 02:20 PM  


$xl= new-object -com Excel.Application
$xl.visible = $true
$wb = $xl.workbooks.open("D:\Book1.xls")

#select a particular sheet as the active sheet using it's name
$sheet2 = $wb.worksheets.item("sheet2")

# activate the sheet
$sheet2.activate()

# set reference to a particular cell
$cell = $sheet2.range("C6")
$cell.value


You can find which members are exposed by piping the objec(s) to get-member, for instance:

PS > $cell | gm


There is also a cool way to generate excel vba code and then translate it into PowerShell. The trick is to record a macro, when you've finished recording press ALT+F11 and then expand the Modules node on the left pane. You'll see the generated code there.

HTH

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
jason_stephensUser is Offline
New Member
New Member
Posts:15
Avatar

--
24 Sep 2008 04:23 PM  

What would you suggest for finding the next row? I want a really elegant way instead of the brute force way that I have come up with.

Thanks for all your help.

ShayUser is Online
Basic Member
Basic Member
Posts:281
Avatar

--
24 Sep 2008 05:13 PM  
Can you elaborate on the next row? Sharing your code can be helpfull
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
jason_stephensUser is Offline
New Member
New Member
Posts:15
Avatar

--
24 Sep 2008 05:45 PM  

Sorry. It made sense when I wrote it :)

$objWorksheet.Cells.SpecialCells(11).Activate()

The above is what I have come up with from my wussy google skills. I am trying to put my active cell to the last row in an excel document. I am wanting to create a log and have the script append every day to the log.

My ultimate goal is to have a powershell script scheduled to run every day that goes out and grabs drive data and SQL information. Basically I need to monitor all my sql servers so I can see their growth and if I need to add drive space before something breaks.

So, is the line above the best way to find the last row in a document?

jason_stephensUser is Offline
New Member
New Member
Posts:15
Avatar

--
24 Sep 2008 05:58 PM  

# Start Microsoft Excel and open RxReconcile log
$objExcel = New-Object -comobject Excel.Application
$objExcel.visible = $true
$objWorkbook = $objExcel.Workbooks.Open("I:\SQL\SQL.xls")
# Select a particular named sheet
$objWorksheet = $objWorkbook.worksheets.Item("AAMCHTM2")
$objWorksheet.Activate()
# Make the next available row active
$objWorksheet.Cells.SpecialCells(11).Activate()
# Select a particular cell on the active sheet
#$objCell = $objWorksheet.range("c6")
#$objCell.Activate()

$objCell = get-date

# Save and shut down excel
$objWorkbook.Save()
$objExcel.Quit()
Stop-Process -processname excel

 

ShayUser is Online
Basic Member
Basic Member
Posts:281
Avatar

--
25 Sep 2008 12:00 PM  
See this links:

http://www.mrexcel.com/archive2/20800/23689.htm
http://www.mrexcel.com/td0058.html
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer