how to create excel file when clicking on the button.

  • Thread starter Thread starter areddy
  • Start date Start date
A

areddy

Hi All,

I have one vb form in that one button is there.when I click on the
button
Excel file should create in "C:\Program Files\Admin\test" path.

I don't want to open the excel file when click on the button just i
want create the excel file in above specified path.

This is the code iam writing under button _click event

Dim objExcel As Excel. Application

Set objExcel = New Excel.Application

What are the next lines.

Please help me on this.

thanks,
Amar...
 
Hi areddy:

Try something like:

Dim objExcel As Excel.Application
Dim wbk As Workbook
Set objExcel = New Excel.Application
objExcel.Visible = True
Set wbk = objExcel.Workbooks.Add
wbk.Worksheets(1).Range("A1") = "OK"
wbk.SaveAs FileName:="C:\123.xls"
Set wbk = Nothing
objExcel.Quit
Set objExcel = Nothing
 
Back
Top