Visual Basic and excel problems, need to get vb to read data from a file and input into vb

visual basic , vba , excel Bristol, United Kingdom
  • 11 years ago
    Hi, I am incredibly new to visual basic and i need to create a programme which reads data from a file and sends it into a cell in an excel spreadsheet. does anyone know how to do this? Cheers in advance
  • 11 years ago
    Hi fuze, 1) To read data: specify pathname, filename and then use INPUT(.........) command 2) To output to excel you can use modified (for your application) the following code: Startcell = 4 'Adjust as required Set XL = CreateObject("Excel.Sheet") 'Create an Excel object With XL.Application .Range("A1:K52").ColumnWidth = 10 .Cells(1, 1).Font.Bold = True .Cells(1, 1).Font.Underline = True .Cells(1, 1).Font.Size = 24 .Cells(1, 1).value = "XXXXXXXXXXXXXX" .Range("A3").Font.Bold = True .Cells(3, 1).value = "Date and Time of Calculation:" .Cells(3, 4).value = Format(Now, "ddddd") '28/05/07 11:22:33 .Cells(3, 5).value = Format(Now, "hh:mm") .Range("A5:A6").Font.Bold = True .Range("A5:A6").Font.Size = 12 .Cells(5, 1).value = "YYYYYYYYYYYYYYY: " .Cells(6, 1).value = Section ' section is some variable - put it to some value while testing .Cells(Startcell + 4, 1).Font.Bold = True .Cells(Startcell + 4, 1).value = "The input data for the calculation:" ........... and then end with! End With File1 = FreeFile XL.SaveAs OutputFile ' Let OutputFile = "D:\xlout.xls" say XL.Application.Quit Set XL = Nothing I hope this helps.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” - Dennis Ritchie