Learn how to a build a cloud-first strategyRegister Now


.doc to csv convert

Posted on 2008-11-13
Medium Priority
Last Modified: 2012-05-05
I have a .doc file that I need to convert to .csv. Each record has 8 lines. ie:

Oz Accomodations
FirstName LastName
123 Main Road
City KS, 66214
Phone: 913-555-1212
Fax: 913-555-1234
firstname-lastname at adomain.zzz

need to convert each record into one line .csv file. I had the instructions and now cannot find them.
** edited the sample above so there is no chance it has personal info - b0lsc0tt **

Open in new window

Question by:akiles99
  • 4
  • 3
LVL 35

Expert Comment

by:Joseph Daly
ID: 22955585
Well heres how I did it.

1. Open the doc in word
2 Select all text and copy
3. Open Excel
4. Select cell A1 and select past special
5. select the option to paste text only

At this point you should have something that looks similar to your word doc but in excel.

7. Select each the rows for each entry and copy.
8. Paste special and then transpose. The entry will now be in a single line
9 Repeat for all the other entries

I have attached an excel doc where you are ready to perform the copy/paste special transpose step.

Author Comment

ID: 22955619

I know how to use transpose i'm looking for an better option like any macros.Since it has 200 records...
LVL 54

Accepted Solution

b0lsc0tt earned 2000 total points
ID: 22969218
I came up with some VBA code that would do this for you.  The code is in the snippet below.  To use it you need to open the VB Editor in Word (Alt + F11).  Access a code page for the sheet or workbook and paste the routine below in.  You can run it in the editor and it will create a new file as you need it.  You would then need to save it with the name you want.
Let me know if you have a question or need more info to use it.

Sub Convert2CSV()
    Dim p As Paragraph
    Dim str As String
    Dim line As String
    For Each p In ActiveDocument.Paragraphs
        line = Trim(Replace(Replace(p.Range.Text, Chr(13), ""), Chr(10), ""))
        If line = "" Then
            str = Left(str, Len(str) - 1) & vbCrLf
            str = str & """" & line & ""","
        End If
    'MsgBox str
    Set oDoc = Application.Documents.Add
    ActiveDocument.Range.Text = str
End Sub

Open in new window

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 22969459

It is working fine.This is a word macro right?

LVL 54

Expert Comment

ID: 22969753
I believe it would actually be considered VBA script.  From what I have read macros are used less and even seem to have changed.  Maybe that is just a change and not really a sign they aren't supported.  I still see the option to Record and depending on how you try to run that routine it could be accessed from a "macros" list.  I guess the answer is at least partially Yes, it is a macro but I don't know that I would use that term for it.  Since I make the scripts and run them from the VB Editor I have thought there was a difference.  If you are curious about the difference it would be worth opening a question for it.  I am sure other experts can explain the difference better or even just how the words are used.
I am glad it did what you need.  Let me know if you have any other questions for this.

Author Closing Comment

ID: 31516585
Thank u Mr.Admin:)Really thanks for ur time....
LVL 54

Expert Comment

ID: 23014749
I'm glad I could help.  Thanks for the grade, the points and the fun question.

Author Comment

ID: 23015124
Actually i like to learn what are the things we could make using word and excel that's why i have posted the question.

And got a result from an expert...

Thanks for ur help...

EE rocks!!!

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

810 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