LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Merging 2 excel file into single excel

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


 
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
Single Excel File Unable to Open L.A. Lawyer Excel Discussion (Misc queries) 6 April 23rd 07 07:36 AM
merging single worksheet files into a single workbook DDK Excel Discussion (Misc queries) 1 December 5th 06 05:25 PM
merging data from 1 excel file, into a master excel file motSwE New Users to Excel 2 September 13th 06 06:39 PM
Save a single worksheet in Excel as a single file. Dakota New Users to Excel 4 February 22nd 06 04:46 PM
Sharing of one single Excel file/workbook Jk Excel Worksheet Functions 1 July 6th 05 06:57 PM


All times are GMT +1. The time now is 04:53 PM.

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"