Solved

use pipe as delimiter

Posted on 2014-02-18
7
462 Views
Last Modified: 2015-03-02
I need a way to export some data from either google spreadsheets or excel.  The catch is i need to use a pipe | as a delimiter.  I do not want to have to change my region settings in windows each time to do this.  Im hoping someone can point me to either an excel macro or google spreadsheet script that will do this.
0
Comment
Question by:colonialiu20
  • 4
  • 3
7 Comments
 
LVL 81

Expert Comment

by:byundt
ID: 39869168
Microsoft Excel MVP Chip Pearson gives code to save some data as a text file using a user-specified delimiter at http://www.cpearson.com/excel/ImpText.aspx "Exporting And Import Text With Excel"

You would use Mr. Pearson's ExportToTextFile sub with a macro like this:
Sub DoTheExport() 
     ExportToTextFile FName:="C:\Test.txt", Sep:="|", _
        SelectionOnly:=False, AppendData:=False
 End Sub

Open in new window

0
 

Author Comment

by:colonialiu20
ID: 39869240
That does not appear to be working.  see attachment.  I can't get it to generate a file.
pipe.xls
0
 
LVL 81

Expert Comment

by:byundt
ID: 39869246
I changed the code to this:
Sub DoTheExport()
ExportToTextFile FName:="X:\VBA\Sample '14\Test.txt", Sep:="|", _
       SelectionOnly:=False, AppendData:=False
End Sub

Open in new window

And got the following results:
Sample results
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:colonialiu20
ID: 39869256
I'm running this on a mac.  any difference?  see my attached spreadsheet.  when i run the macro, i do not get any errors, yet nothing appears in my directory.
pipe.xls
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39869303
You need to write the path correctly to use the code on a Mac. The path separator is a colon instead of slash.

The following code is producing the same result as previously posted when I ran this sub using Excel 2011 (Mac):
Sub DoTheExport()
ExportToTextFile FName:="MacSSD512:Users:byundt:Desktop:Old HP drive:VBA:Sample '14:Test.txt", Sep:="|", _
       SelectionOnly:=False, AppendData:=False
End Sub

Open in new window


I put the following statement in the Immediate pane to get the path of the .xls workbook:
?ActiveWorkbook.FullName

After typing the above statement, hit Enter. You should see the path in the very next line of the Immediate pane. I copied that path (deleting the file name of course) into the code.

Brad
0
 
LVL 81

Expert Comment

by:byundt
ID: 39869308
colonialiu20,
For future reference, it is always a good idea to post the version of Excel that you are using when asking a question in a forum. This is especially true if you are using a Mac.

You can put the Excel version in the question title, question body or question tags. The more common approach at Experts Exchange is to use the tags.

Brad
0
 

Author Closing Comment

by:colonialiu20
ID: 39869333
very responsive!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

You can provide a virtual interface for remote stakeholders in a SWOT analysis through a Google Drawing template. By making real time viewing and collaboration possible, your team can build a stronger product.
Learn about cloud computing and its benefits for small business owners.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

777 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