,
Share this with your friends 
 

Working on Excel applications using VB

0 ratings Views 685 
Author: Anil_aeab20c (Anil Naik)  View Profile |  View other solutions by this author

Question / Problem


Working on Excel applications using VB

Solution

Creating an excel sheet
______________________________________
set xlapp=createobject("excel.application")
xlapp.visible=true
set wbook=xlapp.workbooks.add()
wbook.saveas("C:\Users\Anil\Desktop\sample coding\sample.xls")
wbook.close
xlapp.quit


Adding a parameter in the cell
_____________________________________
set xlapp=createobject("excel.application")
xlapp.visible=true
set wbook=xlapp.workbooks.add()
wbook.saveas("C:\Users\Anil\Desktop\sample coding\sample.xls")
set wsheet=wbook.worksheets(1)
wsheet.cells(1,1)="Anil"
wbook.save
wbook.close
xlapp.quit


Retrieving values from the excel
_____________________________________
set xlapp=createobject("excel.application")
xlapp.visible=true
set wbook=xlapp.workbooks.add()
wbook.saveas("C:\Users\Anil\Desktop\sample coding\sample.xls")
set wsheet=wbook.worksheets(1)
wsheet.cells(1,1)="Anil"
v=wsheet.cells(1,1).value
msgbox v
wbook.save
wbook.close
xlapp.quit


Deleting values from the excel
____________________________________
set xlapp=createobject("excel.application")
xlapp.visible=true
set wbook=xlapp.workbooks.add()
wbook.saveas("C:\Users\Anil\Desktop\sample coding\sample.xls")
set wsheet=wbook.worksheets(1)
wsheet.cells(1,1).delete
wbook.save
wbook.close
xlapp.quit


deleting particular rows from excel
_____________________________________
Set aa = CreateObject("Excel.Application")
Set bb = aa.Workbooks.Open("C:\es.xls")
Set cc = aa.worksheets("Sheet1")
cc.Rows(1).Delete
bb.Save
aa.Workbooks.Close()


rowcount and column count
_____________________________________
set xlapp=createobject("excel.application")
xlapp.visible=true
set wbook=xlapp.workbooks.open("filepath")
set wsheet=wbook.woprksheets(1)
rc=wsheet.usedrange.rows.count
cc=wsheet.usedrange.columns.count
msgboc rc
msgbox cc
wbook.save
wbook.close
xlapp.quit


borders and linestyles
_____________________________________
wsheet.range("A1:D3").select
wsheet.range("A1:D3").borders.linestyle=1
wsheet.shapes.addchart 44


saving the excel file with the current date and time
____________________________________________________

timestamp="test results as on" & day(date)&"_"&monthname(month(date))
&"_"&year(date)&"_"&hour(time)&"_"&minute(time)
wbook.saveas "F:\Frameworks\HDAFW\Test_Results\"&timestamp&".xls"

Applies to

VB 2005

Rank It

Login to rank it

Report


Advertisement