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

create an excel workbook

Status
Not open for further replies.

vttech

Technical User
Jan 28, 2006
297
US
I am using vb 2005 and I am tring to create an Excel Workbook called LeaveRequest.xls
and Add Employee Name: to cell A5 in sheet1. Below is the code I have so far. can someone help me complete the code? or guide me in the right direction.


Code:
 Dim excel As Microsoft.Office.Interop.Excel.Application
 Dim wb As Microsoft.Office.Interop.Excel.Workbook
        
 excel = New Microsoft.Office.Interop.Excel.Application
 wb = New Microsoft.Office.Interop.Excel.Workbook

 'Create Workbook called LeaveRequest.xls

 'Add Employee Name: to cell A5 in sheet1


 'excel.Quit()

Newbie in search of knowledge
 
Try the MS knowlege base Articles ID 301982 or 306022.
Good luck,
djj
 
you need not "create a workbook". after the new Workbook-Call you have a workbook. you only need to save it with the desired name.

for writing data in a cell, you have to access it via worksheet, e.g. wb.Sheets(1) is the first worksheet.

Code:
wb.Sheets(1).Range("A5").Value = "theName"

writes something in a specific cell.

but as djj55 mentioned try to learn some fundamentals by reading a book or some websites/articles
 

I am trying to merge cell A1 through I1; how is this done?
tried excel.Range("Al").Merge("i1")

Code:
Dim excel As Microsoft.Office.Interop.Excel.Application

excel = New Microsoft.Office.Interop.Excel.Application


Create Workbook called LeaveRequest.xls

excel.Visible = True
excel.Workbooks.Add()
excel.Range("Al").Merge("i1")

Newbie in search of knowledge
 
Hello,
Since you need to merge the cells your range would be:
Code:
excel.Range("A1:I1").Select
Then you need to create the merge. I cannot remember how to do the merge but here is how it is done if VBA this is NOT how it is done in VB.NET, but you can get ideas on what needs done.
Code:
With Selection
    .HorizontalAlignment = xlGeneral
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = True
End With
Good Luck,
djj
 
Declare a Range object, assign the required range to it and then you can use MyExcelRange.MergeCells = True


Hope this helps.




[vampire][bat]
 


Declare a Range object, assign the required range to it and then you can use MyExcelRange.MergeCells = True


step 1 Declare a range

Code:
Dim myExcelRange As Microsoft.Office.Interop.Excel.Range

How do you assign a range to that object? For this example A1 through I1

Newbie in search of knowledge
 
Thanks for the help the answer was

Code:
excel.Range("A1", "I1").MergeCells = True

Newbie in search of knowledge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top