+ Reply to Thread
Results 1 to 4 of 4

Need vba code: How to export 2 column sheet to textfile / import textfile to 2 columns

  1. #1
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    69

    Need vba code: How to export 2 column sheet to textfile / import textfile to 2 columns

    Hi everyone,

    I need your help.
    I have a worksheet called Contacts.
    Column A is Contact Name
    Column B is Contact Number
    I would like to do a backup of the 2 columns and export it into a text file.
    I would like to do a restore, import the textfile into the 2 columns.
    Here is the code I currently have, it exports it into a textfile but when I import it back, it writes everyting in column A.
    Also attached the actual workbook.

    Thank you in advance.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Need vba code: How to export 2 column sheet to textfile / import textfile to 2 columns

    If you're going to write it with ADODB.Stream then perhaps you should read it using the same. See below:

    Please Login or Register  to view this content.
    Note I made a small change to the Backup routine to close the stream. I mostly re-wrote the restore routine.

    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    69

    Re: Need vba code: How to export 2 column sheet to textfile / import textfile to 2 columns

    Sweet, I got an error however in the Restore routine at: .Type = adTypeText, I changed it to .Type = 2 and it works like magic now.
    Thanks a lot, it's exactly what I was looking for. You are a star!

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Need vba code: How to export 2 column sheet to textfile / import textfile to 2 columns

    Quote Originally Posted by frankytheman View Post
    Sweet, I got an error however in the Restore routine at: .Type = adTypeText, I changed it to .Type = 2 and it works like magic now.
    Thanks a lot, it's exactly what I was looking for. You are a star!
    Oops. Yes. I had a reference to the ADODB library in my code - sorry about that. Glad it's working for you

    WBD

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Export/import between Excel and textfile
    By Axmed.cm in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-13-2017, 05:38 PM
  2. Implementing TextFile import Delimiter settings on TXT Import VBA Script
    By Canuckle777 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-19-2013, 02:06 PM
  3. Macros code to Import textfile to existing sheet
    By luckygrass711 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2012, 10:51 PM
  4. Import textfile to excel
    By Petter120 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2012, 05:13 PM
  5. [SOLVED] Import textfile to excel and split (spaces) to column !
    By Petter120 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-09-2012, 02:04 PM
  6. Pick textfile in combobox and read last entry in textfile to sheet!
    By Petter120 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-09-2012, 07:11 AM
  7. Export as Textfile with VBA
    By moondark in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2005, 09:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1