LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBS Script and ClearContents -- Code Throws An Error

Need VBS script to clear the contents for range all worksheets in workbook.
Must run as VBS script. Having issue with line

"currentWorkSheet .Range( cellRange ).ClearContents"; error generated

excelPath = "<Enter a UNC path to a workbook with 1+ worksheets"
cellRange = "A1:Z100"

WScript.Echo "Reading Data from " & excelPath
WScript.Echo "cellRange = " & cellRange

Set oExcel = CreateObject("excel.application")
oExcel.Workbooks.open( excelPath )

workSheetCount = oExcel.Worksheets.Count

WScript.Echo "We have " & workSheetCount & " worksheets"

For counter = 1 to workSheetCount
WScript.Echo "Reading data from worksheet " & counter & vbCRLF

Set currentWorkSheet = oExcel.ActiveWorkbook.Worksheets( counter )

WScript.Echo "Call to Range method next" & vbCrLf

currentWorkSheet .Range( cellRange ).ClearContents ' <-- Fails

Set currentWorkSheet = Nothing
Next

oExcel.Workbooks(1).Close
oExcel.Quit

Set currentWorkSheet = Nothing
Set oExcel = Nothing



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Throws Error 91 Dave Birley Excel Programming 13 May 17th 07 07:01 PM
workbook.open throws 1004 error [email protected] Excel Programming 3 April 3rd 06 11:37 PM
How do I perform a certain function if VBA throws up an error? Matt[_37_] Excel Programming 2 February 24th 06 03:06 PM
[Q] Save As throws type mismatch error in control's code? Jason Weiss Excel Discussion (Misc queries) 1 July 16th 05 04:21 AM
Format statement no longer throws an error PF[_2_] Excel Programming 6 March 4th 04 02:44 PM


All times are GMT +1. The time now is 06:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"