Reply
 
Thread Tools Display Modes
  #1   Report Post  
Clint
 
Posts: n/a
Default Filling Table with csv file

I'm trying to create a transmittal letter with a list of drawings. The list
of drawing information is in a csv file and I want to create a template that
will take this csv file and create a list of the drawing information. In
other words all the information from the csv file listed on one letter.
Help!!! I tried to use mail merge but all I'm getting is the first record.
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

Clint wrote:
I'm trying to create a transmittal letter with a list of drawings.
The list of drawing information is in a csv file and I want to create
a template that will take this csv file and create a list of the
drawing information. In other words all the information from the csv
file listed on one letter. Help!!! I tried to use mail merge but all
I'm getting is the first record.


If you have Excel, open the csv file in that program -- Excel understands
csv, while Word considers it just plain text. Then select the cells in
Excel, copy to the clipboard, and paste into Word. The result will be a
table.

Without Excel, you can open or paste the csv data into Word, select it, and
run Table Convert Text to Table. Make sure the "Commas" option is
selected for the separator and click OK. The result will be a table similar
to the one you'd get from Excel, but formatted somewhat differently.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


  #3   Report Post  
Clint
 
Posts: n/a
Default

I want this done as a template. So when a user opens the template it will
update the list of drawings for each transmittal letter. The csv file is
always named the same....

"Jay Freedman" wrote:

Clint wrote:
I'm trying to create a transmittal letter with a list of drawings.
The list of drawing information is in a csv file and I want to create
a template that will take this csv file and create a list of the
drawing information. In other words all the information from the csv
file listed on one letter. Help!!! I tried to use mail merge but all
I'm getting is the first record.


If you have Excel, open the csv file in that program -- Excel understands
csv, while Word considers it just plain text. Then select the cells in
Excel, copy to the clipboard, and paste into Word. The result will be a
table.

Without Excel, you can open or paste the csv data into Word, select it, and
run Table Convert Text to Table. Make sure the "Commas" option is
selected for the separator and click OK. The result will be a table similar
to the one you'd get from Excel, but formatted somewhat differently.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



  #4   Report Post  
Jay Freedman
 
Posts: n/a
Default

OK, that's doable. The UpdateTableFromCSV() macro below automates the
"convert to table" method that I mentioned before.

Put these three macros in a module in your template (see
http://www.gmayor.com/installing_macro.htm if you need instructions). Change
the path and name of the csv file (in the line that defines the variable
csvFileName) to the one you use.

Public Sub AutoNew()
UpdateTableFromCSV
Dialogs(wdDialogFileSaveAs).Show
End Sub

Public Sub AutoOpen()
UpdateTableFromCSV
ActiveDocument.Save
End Sub

Private Sub UpdateTableFromCSV()
Dim oRg As Range
Dim oDoccsv As Document
Dim csvFileName As String

csvFileName = _
"C:\Documents and Settings\Clint\My Documents\Data.csv"

Set oRg = ActiveDocument.Bookmarks("csv_here").Range

On Error Resume Next
Set oDoccsv = Documents.Open( _
FileName:=csvFileName, _
ConfirmConversions:=False, _
Format:=wdOpenFormatText)
If Not oDoccsv Is Nothing Then
With oRg
Do While .Tables.Count
.Tables(1).Delete
Loop

.Text = oDoccsv.Content.Text

oDoccsv.Close savechanges:=wdDoNotSaveChanges
Set oDoccsv = Nothing

.Style = ActiveDocument.Styles("Normal")
.ConvertToTable Separator:=","
End With
ActiveDocument.Bookmarks.Add Name:="csv_here", _
Range:=oRg.Tables(1).Range
Else
MsgBox "Could not find " & csvFileName
End If
End Sub

Add a bookmark named "csv_here" in the body of the template and save it.
Then use File New to create a document based on the template. Each time
you create a new document or open an existing document based on this
template, the table will be updated to the current contents of the csv file.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

Clint wrote:
I want this done as a template. So when a user opens the template it
will update the list of drawings for each transmittal letter. The
csv file is always named the same....

"Jay Freedman" wrote:

Clint wrote:
I'm trying to create a transmittal letter with a list of drawings.
The list of drawing information is in a csv file and I want to
create a template that will take this csv file and create a list of
the drawing information. In other words all the information from
the csv file listed on one letter. Help!!! I tried to use mail
merge but all I'm getting is the first record.


If you have Excel, open the csv file in that program -- Excel
understands csv, while Word considers it just plain text. Then
select the cells in Excel, copy to the clipboard, and paste into
Word. The result will be a table.

Without Excel, you can open or paste the csv data into Word, select
it, and run Table Convert Text to Table. Make sure the "Commas"
option is selected for the separator and click OK. The result will
be a table similar to the one you'd get from Excel, but formatted
somewhat differently.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



  #5   Report Post  
Clint
 
Posts: n/a
Default

Thanks, this really helped

"Jay Freedman" wrote:

OK, that's doable. The UpdateTableFromCSV() macro below automates the
"convert to table" method that I mentioned before.

Put these three macros in a module in your template (see
http://www.gmayor.com/installing_macro.htm if you need instructions). Change
the path and name of the csv file (in the line that defines the variable
csvFileName) to the one you use.

Public Sub AutoNew()
UpdateTableFromCSV
Dialogs(wdDialogFileSaveAs).Show
End Sub

Public Sub AutoOpen()
UpdateTableFromCSV
ActiveDocument.Save
End Sub

Private Sub UpdateTableFromCSV()
Dim oRg As Range
Dim oDoccsv As Document
Dim csvFileName As String

csvFileName = _
"C:\Documents and Settings\Clint\My Documents\Data.csv"

Set oRg = ActiveDocument.Bookmarks("csv_here").Range

On Error Resume Next
Set oDoccsv = Documents.Open( _
FileName:=csvFileName, _
ConfirmConversions:=False, _
Format:=wdOpenFormatText)
If Not oDoccsv Is Nothing Then
With oRg
Do While .Tables.Count
.Tables(1).Delete
Loop

.Text = oDoccsv.Content.Text

oDoccsv.Close savechanges:=wdDoNotSaveChanges
Set oDoccsv = Nothing

.Style = ActiveDocument.Styles("Normal")
.ConvertToTable Separator:=","
End With
ActiveDocument.Bookmarks.Add Name:="csv_here", _
Range:=oRg.Tables(1).Range
Else
MsgBox "Could not find " & csvFileName
End If
End Sub

Add a bookmark named "csv_here" in the body of the template and save it.
Then use File New to create a document based on the template. Each time
you create a new document or open an existing document based on this
template, the table will be updated to the current contents of the csv file.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

Clint wrote:
I want this done as a template. So when a user opens the template it
will update the list of drawings for each transmittal letter. The
csv file is always named the same....

"Jay Freedman" wrote:

Clint wrote:
I'm trying to create a transmittal letter with a list of drawings.
The list of drawing information is in a csv file and I want to
create a template that will take this csv file and create a list of
the drawing information. In other words all the information from
the csv file listed on one letter. Help!!! I tried to use mail
merge but all I'm getting is the first record.

If you have Excel, open the csv file in that program -- Excel
understands csv, while Word considers it just plain text. Then
select the cells in Excel, copy to the clipboard, and paste into
Word. The result will be a table.

Without Excel, you can open or paste the csv data into Word, select
it, and run Table Convert Text to Table. Make sure the "Commas"
option is selected for the separator and click OK. The result will
be a table similar to the one you'd get from Excel, but formatted
somewhat differently.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org




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
How to creat relative and shorthand file path names? 2dogs Microsoft Word Help 1 May 15th 05 12:11 PM
How can I insert a text file into a table? Lua_Lua Tables 1 May 10th 05 05:07 PM
Table headers/footers and layout Keith Page Layout 1 April 8th 05 07:37 PM
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM
how do i determine end of table in MS word file? Alpesh Patel Tables 1 October 27th 04 07:04 AM


All times are GMT +1. The time now is 04:17 PM.

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"