Reply
 
Thread Tools Display Modes
  #1   Report Post  
_Mario_
 
Posts: n/a
Default Create table in word from csv

Hi all,
I need to import a csv as a table in a word document with a macro.

How can I do this?

Can anyone send me a snippet of code?

Thanks.


Mario


  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

Open the file in Word, select all of the text and then from the Table menu
select Convert text to table. In the dialog that appears, check the
appropriate separator and you should get a table.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
"_Mario_" wrote in message
...
Hi all,
I need to import a csv as a table in a word document with a macro.

How can I do this?

Can anyone send me a snippet of code?

Thanks.


Mario



  #3   Report Post  
Graham Mayor
 
Posts: n/a
Default

Word will not import a csv file as a table. You can convert it to a table
once imported. Though how successful this will be will depend on the content
of the CSV and how easily Word can determine what are fields and what are
records.
The following may help you on your way:

Documents.Open ("d:\path\filename.csv")
Selection.WholeStory
Selection.ConvertToTable Separator:=wdSeparateByCommas
End Sub

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





_Mario_ wrote:
Hi all,
I need to import a csv as a table in a word document with a macro.

How can I do this?

Can anyone send me a snippet of code?

Thanks.


Mario



  #4   Report Post  
_Mario_
 
Posts: n/a
Default


"Graham Mayor" wrote in message
...

The following may help you on your way:

Documents.Open ("d:\path\filename.csv")
Selection.WholeStory
Selection.ConvertToTable Separator:=wdSeparateByCommas
End Sub


That seems to be usefull... but what do U think about creating a Excell app.
that load the csv, select all cells and then paste them imto the word doc?

Mario


  #5   Report Post  
Doug Robbins
 
Posts: n/a
Default

No better or worse.

If you have (or added) a paragraph at the top of the .CSV file to hold
mergefield names, you could also use a catalog (or in Word XP or later, a
directory) type mailmerge with the mergefields inside the cells of a one row
table in the mailmerge main document. Then when you execute the merge, the
data from each record will be inserted into a row in a table that is
created.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
"_Mario_" wrote in message
...

"Graham Mayor" wrote in message
...

The following may help you on your way:

Documents.Open ("d:\path\filename.csv")
Selection.WholeStory
Selection.ConvertToTable Separator:=wdSeparateByCommas
End Sub


That seems to be usefull... but what do U think about creating a Excell
app. that load the csv, select all cells and then paste them imto the word
doc?

Mario



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
In typing dates in Word, i.e. "January 12" how do you keep the "1. Carol Microsoft Word Help 2 January 12th 05 08:09 PM
word xp crashes after macros are recorded kharris0405 Microsoft Word Help 3 January 11th 05 10:50 PM
WP Delay Code - Word Equiv Mike G - Milw, WI Microsoft Word Help 6 January 10th 05 04:12 PM
Continuous breaks convert to next page breaks Jennifer Hunt Microsoft Word Help 2 December 30th 04 05:45 PM
macro in word js Microsoft Word Help 1 December 28th 04 03:01 AM


All times are GMT +1. The time now is 05:07 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"