Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Excel - Delete rows above 9

Status
Not open for further replies.

pvong

MIS
Jul 16, 2003
7
US
I'm very very new at this. I'm trying to create a vbscript that will open
an Excel 2003 file and delete all rows above 9. This is the code I came up
with.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook =
objExcel.Workbooks.Open("D:\ServerFiles\CroftDB\DbImport\dbaum.xls")
rows(9).Offset(-x).Resize(x).delete
objExcel.Quit

The error message I'm getting says Line 4.
Type Mismatch: 'rows'
Code: 800A000D

I Googled the code number and I didn't understand most of what I'm reading.
Please help a very newbie out. I just want to delete all rows above 9 in
Sheet1. This VBScript is running on my Win2003 server and I'm using Excel
2003.

Thanks in advance.

Phil

 
And what about this ?
objExcel.ActiveSheet.Rows("1:9").Delete

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PH - AWSOME THANKS!!!

When the script runs, I get a pop-up asking if I want to save the changes. What do I add if I just want it to save over itself?
 
objExcel.ActiveWorkbook.Close True
objExcel.Quit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK, it's not perfect. Can someone show me how to save the file as a CSV after it takes out the rows? I would like to use the same filename. I would also like this done without human interaction.

Thanks!
 
maybe...

Const xlCSV = 6

objExcel.ActiveWorkbook.SaveAs "D:\ServerFiles\CroftDB\DbImport\dbaum.csv", xlCSV
objExcel.Quit

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Here my complete code:

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("D:\ServerFiles\CroftDB\DbImport\dbaum.xls")
objExcel.ActiveSheet.Rows("1:7").Delete
objExcel.ActiveSheet.Columns("B").Delete
objExcel.ActiveWorkbook.Close True
Const xlCSV = 6
objExcel.ActiveWorkbook.SaveAs "D:\ServerFiles\CroftDB\DbImport\dbaum.csv", xlCSV
objExcel.Quit

I get an error in line 7. It says (Object Required: 'objExcel.ActiveWorkbook')

Thanks!
 
Set objExcel = CreateObject("Excel.Application")
strWB = "D:\ServerFiles\CroftDB\DbImport\dbaum."
Set objWorkbook = objExcel.Workbooks.Open(strWB & "xls")
objExcel.ActiveSheet.Rows("1:7").Delete
objExcel.ActiveSheet.Columns("B").Delete
Const xlCSV = 6
objExcel.ActiveWorkbook.SaveAs strWB & "csv", xlCSV
objExcel.Quit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
WE ARE SOOO CLOSE. Any chance you know how I can make it save the CSV without asking me all those questions? I have to hit all those YES...etc. I'm trying to automate this process.

Thanks in advance.

P.S. This is my first time at this forum and it's great. You people are quick and good.
 
Set objExcel = CreateObject("Excel.Application")
[!]objExcel.DisplayAlerts = False[/!]
strWB = "D:\ServerFiles\CroftDB\DbImport\dbaum."
Set objWorkbook = objExcel.Workbooks.Open(strWB & "xls")
objExcel.ActiveSheet.Rows("1:7").Delete
objExcel.ActiveSheet.Columns("B").Delete
Const xlCSV = 6
objExcel.ActiveWorkbook.SaveAs strWB & "csv", xlCSV
objExcel.Quit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top