Jump to content

Recommended Posts

Posted

Effectively you want to clear the entire sheet right? Try this:

$sheet = 1 ;can be sheet number or name
$oExcel.ActiveWorkbook.Sheets($sheet).Select ()
$oExcel.Cells().ClearContents

Posted

Hi,

i suppose you haven't have an excel object. See helpfile _ExcelBookOpen() or _ExcelBookAttach().

This must be before $oExcel.ActiveWorkBook....

$oExcel = _ExcelBookOpen ("<fullpath to excelworkbook>") ; or your sheet is in ScriptDir
;$oExcel = _ExcelBookOpen ("workbookname.xls")
;cleaning contents of 1.st sheet in workbook
$sheet = 1 ;can be sheet number or name
$oExcel.ActiveWorkbook.Sheets($sheet).Select ()
$oExcel.Cells().ClearContents

;-))

Stefan

Posted

I assume too much :( thanks 99ojo.

@AnuReddy: Don't forget to finish with:

_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel)

Otherwise your changes won't be saved, or excel will keep running in the background.

Posted

$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = 1
$oExcel.WorkBooks.Open ("C:\file.xls")
$oExcel.ActiveSheet.UsedRange.ClearContents

Posted (edited)

$oExcel = ExcelAttach($path)

$oExcel.Application.ActiveSheet.UsedRange.clearcontents()

This is working fine for a particular active sheet but if i a particular sheet to be identified by name and then clear the contents its not working fine

Edited by AnuReddy

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...