Solved

writing data into an excel file

Posted on 2003-11-19
3
592 Views
Last Modified: 2010-05-01
i need to write some data through my VB code into an existing excel file at a particular cell location. how do i do this?
0
Comment
Question by:RTKVSNL
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
rajaamirapu earned 75 total points
ID: 9785153
Include excel 9 object library.
dim ex as excel.application
Set Ex = New Excel.Application  'intialize excel    
If Not fso.FileExists(txtSourceFolder.Text & "\" & "test.xls") Then
    Set wrkBook = Ex.Workbooks.Add
Else
    Set wrkBook = Ex.Workbooks.Open(txtSourceFolder.Text & "\" & "test.xls")
       
End If

Ex.DisplayAlerts = False
Set wrkSheet = wrkBook.Sheets(2)  'get the current sheet
   
wrkSheet.Name = "xxxx"
'title of the report
'your value here
wrkSheet.Range("C1").ColumnWidth = 20.14
wrkSheet.Range("C1").Value = "xxxx"
You can auto fit also
       
0
 

Author Comment

by:RTKVSNL
ID: 9785203
thanks for the prompt answer. i forgot to mention in my question that at the end i also need to save the file and close it. i am increasing the points of the question so please let me know how to do that
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9785218
wrkBook.SaveAs  YourPath & "\" & filename.xls
wrkBook.Close
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question