There is no single line to delete unused sheets.
You have to check. One way is to look at the used range and see if it's just
A1. Then check to see if A1 is empty. If both those things are true, then the
worksheet is _probably_ not used. But you never know--there could be something
that's being used that doesn't fit either of those rules.
Still untested and I don't use enough VBS to recognize problems just by looking!
dim objWks
dim objXL
dim objWBA
Set objXL = WScript.CreateObject ("Excel.Application")
set objWBA = objxl.workbooks.open("C:\a.xls")
for each objwks in objwba.worksheets
if objwks.usedrange.address = "$A$1" then
if objwks.range("a1").formula = "" then
if objWBA.sheets.count 1 then
objxl.displayalerts = false
objwks.delete
objxl.displayalerts = true
end if
end if
end if
next objwks
======
I would still use a worksheet object--not the application.
objXL.Range("A1:R2").Select 'Select first 2 rows
objXL.Selection.Font.Bold = True
becomes
objWKS.range("a1:R2").font.bold = true
(after you set objwks to something nice.)
======
and
objWks.name = "NewNameHere"
(not one ounce of validation here, though.)
======
objwks.range("a1").entirecolumn.autofit
or
objwks.range("a1:x1").entirecolumn.columnwidth = 23
======
Some place in your code, you may want to use:
set objWks = objXL.Activesheet
or
set objWks = objWBA.Activesheet
or
set objWks = objWBA.worksheets(1)
or
set objWks = objWBA.worksheets("Sheet1")
moonwalker wrote:
Hey,
I tried the code snippet and its working perfectly.
I manage to merge 2 csv files into one single excel file.
However there is still a minor problem.
The excel file i created has Sheet1, 2, 3 and 2 other sheets created
according to the csv file name.
Whats the syntax for deleting the unused sheets and i would like to
know about renaming the sheet name.
I have manage to select the first 2 rows and make them bold.
objXL.Range("A1:R2").Select 'Select first 2 rows
objXL.Selection.Font.Bold = True 'Bold first 2 rows
How can i Adjust the Column Width?
i tried objXL.AdjustColumnWidth = True
but it doesnt have this method
Appreciate your help.
--
moonwalker
------------------------------------------------------------------------
moonwalker's Profile: http://www.excelforum.com/member.php...o&userid=31766
View this thread: http://www.excelforum.com/showthread...hreadid=516471
--
Dave Peterson