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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output vb into one .xls multiple sheets, multiple questions

Status
Not open for further replies.

rborel

MIS
Dec 3, 2002
29
US
If this is a repost please forgive.

I've created a little app that reads from multiple db servers and outputs to a xls. I have the data from each server going to it's own sheet.

1) My first question is, is there any way to output to the xls without using the following due to the fact I'd like to run this in the background without having to open Excel. I know how to output to csv but haven't figured out how to directly input to a xls sheet;

Dim OXL As New Excel.Application
Dim OWB As Excel.Workbook
Dim OSheet As Excel.Worksheet
Dim ORng As Excel.Range
OXL.Visible = True
OWB = OXL.Workbooks.Add
OSheet = OWB.ActiveSheet

To create the new sheet on the next "while" statement run I'm using;
OWB.Sheets.Add()
OSheet = OWB.ActiveSheet
I then rename the ActiveSheet to the name of the server that I'm collecting the data from.

Reason I ask is, the workbook is creating 2 extra sheets(Sheet2 and Sheet3) automatically.

2) Is there a way to delete those extra sheets?

I'd like to inject directly to the xls because I'm pretty sure it'll be faster than having Excel open. When I run the app now it's pretty slow due to the fact that it is adding approximatly 8000 rows to each of the xls worksheets.

3) If I output to multiple csv's is there a way to bring the csv's into an xls with each csv being a new worksheet?

Any assistance would be greatly apprectiated.
 
1. To prevent Excel from opening simply omit the line

OXL.Vislible = True

...or set the property to False

2.I was unable to delete the sheets, however this will hide sheets 2 & 3

oSheet = oWB.Sheets.Item(2)
oSheet.Visible = XlSheetVisibility.xlSheetHidden

oSheet = oWB.Sheets.Item(3)
oSheet.Visible = XlSheetVisibility.xlSheetHidden
 
I figured out the delete:
OXL.DisplayAlerts = False
OWB.Sheets("Sheet1").delete()
OWB.Sheets("Sheet2").delete()
OWB.Sheets("sheet3").select()
OXL.DisplayAlerts = True

I had also found out the .Visible = False when I found the delete information.

Thx for the reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top