Solved

writing data into an excel file

Posted on 2003-11-19
3
591 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net 2008 2 60
JSON Response and request in VB6 application 11 433
Best way to parse out a json string in VB6? 10 174
Recommendation vb6 to vb.net or others 14 150
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

823 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