Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 29th, 2009, 12:40 PM
Authorized User
Join Date: Mar 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to read data form a file using vba to change cells in excel

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!
Old March 30th, 2009, 01:29 AM
Friend of Wrox
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts

if you are reading a textfile and manipulating the contents then you can try FileSystemObject's OpenTextFile or other methods


You can also try workbooks opentext method



C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Old April 6th, 2009, 11:25 AM
Authorized User
Join Date: Mar 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts

Cheers for this, I have tried to do the Input # Statement listed in the first link you gave me. I pasted the code into an excel macro and then ran the macro and no error messages appeared but the data in the text file did not appear in the workbook. all i had in the text file was the number 65.

was this because i didnt specify which cell the data should be entered into? I don't understand this very well as I am new to visual basic but i really need to work out how to do this!

this is the code i put into the macro, am i missing some things?

Thank you very much for the link and help by the way, this is the closest i have got to working it out so far, unfortunately i lack the knowledge of the programme to fill in any gaps whatsoever so it might seem like im asking silly questions!


Sub FIR()

Dim MyString, MyNumber
Open "C:\Users\Ben\Documents\test.txt" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
Input #1, MyString, MyNumber ' Read data into two variables.
Debug.Print MyString, MyNumber ' Print data to the Immediate window.
Close #1 ' Close file
End Sub

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read data from an excel file diegoblin Beginning VB 6 6 August 31st, 2009 11:04 PM
VBA Code to read the structure & data of an excel alam1 Excel VBA 0 April 24th, 2007 11:39 PM
Read Data from Excel File kiwibey ASP.NET 2.0 Professional 1 December 5th, 2006 11:27 AM
VBA Formatting cells with Html tags read from XML hemagiri Excel VBA 0 November 22nd, 2006 02:41 AM
Update excel cells on change of another program pjhlin VB How-To 2 January 20th, 2004 11:56 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.