Solved

Open a csv files with delimiter rather than comma in VBA

Posted on 2011-02-12
6
297 Views
Last Modified: 2012-05-11
How do I open a text file with  exclamation mark as me cell seperator?


        Set xwb = Workbooks.Open(filename)
        Set xWorkSheet = xwb.Sheets(1)

DO I use some other arguement for Workbooks.Open?
0
Comment
Question by:tommym121
  • 3
  • 3
6 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34881382
It should be something like this:

    Workbooks.OpenText Filename:=filename, _
        StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=False, _
        Space:=False, Other:=True, OtherChar:="!", TrailingMinusNumbers:=True
    set swb = ActiveWorkbook
    set xWorkSheet = xwb.Sheets(1)

Open in new window


I hope this helps.
0
 

Author Comment

by:tommym121
ID: 34881428
Does not seems to work with this  file, I use ~ instead of ! for OtherChar:="~"
abc.csv
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34881514
Try changing the file extension to .txt and it should work.  (for example, abc.csv.txt)
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:tommym121
ID: 34883936

wdosanjos:

Thanks.  It works.  But would you mind tell me why adding the new extension will work.   Thanks.
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 34884039
It seems that Excel has a tight control over its extensions, so for those (.csv, .xlsx, .xls, etc) we cannot override their behavior.
0
 

Author Closing Comment

by:tommym121
ID: 34928393
Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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