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 January 19th, 2004, 01:28 PM
Registered User
 
Join Date: Jan 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert data in a text file and export them

Hi for all
This is very hard.
I want to insert into a text file create by Excel some information like name, address and so on.
When the file is opened, excel´s macro waits 'till I save the file.
Then, it copy each line of the text file and put in a excel´s row.
Please HELP MEEEEEEE!!

Hughes for all


Alex

 
Old January 19th, 2004, 01:47 PM
Authorized User
 
Join Date: Dec 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If it is waiting for a 'save' to occur then the macro has that request coded into it...You will need to edit the macro. I am unclear as to what your final goal is...are you trying to write several records into an excel spreadsheet or take excel information and put it into a word (or other text) document.

John

 
Old January 23rd, 2004, 07:28 AM
Authorized User
 
Join Date: Jul 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default

If I understand this correctly, you want to read the text of a text file and place each line of it's text into a row in an Excel worksheet?

If so here's the code to accomplish this (just change the filename from boot.ini):

Private Sub CommandButton1_Click()
    Dim intLoopCounter As Integer
    Dim strTemp As String

    intLoopCounter = 1

    Open "C:\boot.ini" For Input As #1

        Do Until EOF(1)
            Line Input #1, strTemp

            Cells(intLoopCounter, 1) = strTemp
            intLoopCounter = intLoopCounter + 1
        Loop

    Close #1
End Sub


 
Old January 23rd, 2004, 07:31 AM
Authorized User
 
Join Date: Jul 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default

The first part of this (taking each line/row's text from Excel & placing this INTO a text file), can be accomplished by using this:

Private Sub CommandButton1_Click()
    Dim intLoopCounter As Integer
    Dim strTemp As String

    For intLoopCounter = 1 To UsedRange.Rows.Count
        strTemp = strTemp & Cells(intLoopCounter, 1) & vbCrLf
    Next intLoopCounter

    Open "C:\boot1.ini" For Output As #1
        Print #1, strTemp
    Close #1
End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
insert a new line at beginning of text file? how? Satorikin VB.NET 2002/2003 Basics 8 October 15th, 2008 09:55 PM
Most efficient way to insert text into a file StumblingInTheDark Visual Basic 2005 Basics 1 February 22nd, 2007 01:09 PM
Export to text file without exponents Pavesa Access 14 November 24th, 2004 07:44 AM
DTS text file export - Batch Process Tim Barbour SQL Server DTS 1 November 23rd, 2004 11:50 AM
how can I insert a new line at top of text file? Satorikin VB.NET 1 March 4th, 2004 03:41 AM





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