Thursday, December 23, 2010

Create Excel Report

Sub ExcelReport()



' Prepare MS Excel for work
Set xlApp = CreateObject("Excel.Application")


' View Excel object 
      xlApp.Visible = True


' Add new Workbook to excel sheet.
xlApp.Workbooks.add
Set xlsheet = xlApp.Workbooks(1).Worksheets(1)


' Select the Sheet1 and rename it what ever your want...
xlsheet.Activate
xlsheet.Name = "[Sheet Name]"

' Add values/formulas to excel Cells...


xlSheet.Range("A1").Value = "No"
xlSheet.Range("B1").Value = "Name"
xlSheet.Range("B1").Value = "Value"


xlSheet.Range("A2").Value = "1"
xlSheet.Range("A3").Value = "2"
xlSheet.Range("A4").Value = "3"


xlSheet.Range("B2").Value = "ABC"
xlSheet.Range("B3").Value = "PQR"
xlSheet.Range("B4").Value = "XYZ"



xlSheet.Range("C2").Value = "100"
xlSheet.Range("C3").Value = "200"
xlSheet.Range("C4").Value = "300"

xlSheet.Range("B5").Value = "Total Value"
xlSheet.Range("C5").Value = "=Sum(C2:C4)"


End Sub

No comments:

Post a Comment

Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.Please don't spam,spam comments will be deleted upon reviews.