Group:  Microsoft Word ยป microsoft.public.word.docmanagement
Thread: INSERTTEXT field help

Geek News

INSERTTEXT field help
John 12/15/2008 9:23:02 PM
In Excel I have a list of file paths for a large number of word documents.

What I would like to do is have the field INSERTTEXT to look at the cells in
excel and then insert the text to word.

I would also like a table of contents to be created after they have been
included.

thanks for any help

John

INCLUDETEXT field help
John 12/15/2008 9:26:00 PM
Sorry, ment INCLUDETEXT


"John" wrote:

[Quoted Text]
> In Excel I have a list of file paths for a large number of word documents.
>
> What I would like to do is have the field INCLUDETEXT to look at the cells in
> excel and then insert the text to word.
>
> I would also like a table of contents to be created after they have been
> included.
>
> thanks for any help
>
> John
>
Re: INCLUDETEXT field help
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 12/16/2008 10:03:26 AM
You can do this with a macro If you have not already done so add a reference
to Microsoft Excel in vba tools > references


Sub ReadExcelWB()
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim tCell As String
Dim rCount As Long
Dim xlName As String

xlName = "D:\My Documents\Test\ExcelWB.xls"
Documents.Add
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open(xlName)
rCount = 1
With xlWB.Worksheets(1)
While Cells(rCount, 1).Formula <> ""
tCell = Cells(rCount, 1).Formula
With ActiveDocument
Selection.InsertFile FileName:=tCell, Range:="", _
ConfirmConversions:=False, _
Link:=False, Attachment:=False
End With
rCount = rCount + 1
Wend
End With
xlWB.Close False
xlApp.Quit
Set xlWB = Nothing
Set xlApp = Nothing
End Sub

will read a list of documents from column 1 of "D:\My
Documents\Test\ExcelWB.xls" and insert them in order into a new document.
You can add the code to insert an appropriate TOC where you require it at
the end of the macro e.g.

With Selection
.HomeKey Unit:=wdStory
With .Fields
.Add Selection.Range, wdFieldTOC, "\o ""1-3"" \h \z \u", False
.Update
End With
.InsertBreak Type:=wdSectionBreakNextPage
End With
ActiveWindow.View.ShowFieldCodes = False

..
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

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




John wrote:
[Quoted Text]
> Sorry, ment INCLUDETEXT
>
>
> "John" wrote:
>
>> In Excel I have a list of file paths for a large number of word
>> documents.
>>
>> What I would like to do is have the field INCLUDETEXT to look at the
>> cells in excel and then insert the text to word.
>>
>> I would also like a table of contents to be created after they have
>> been included.
>>
>> thanks for any help
>>
>> John


Re: INCLUDETEXT field help
John 12/16/2008 9:56:01 PM
Thanks Grahan,

That was just what I needed
--
John



"Graham Mayor" wrote:

[Quoted Text]
> You can do this with a macro If you have not already done so add a reference
> to Microsoft Excel in vba tools > references
>
>
> Sub ReadExcelWB()
> Dim xlApp As Excel.Application
> Dim xlWB As Excel.Workbook
> Dim tCell As String
> Dim rCount As Long
> Dim xlName As String
>
> xlName = "D:\My Documents\Test\ExcelWB.xls"
> Documents.Add
> Set xlApp = CreateObject("Excel.Application")
> Set xlWB = xlApp.Workbooks.Open(xlName)
> rCount = 1
> With xlWB.Worksheets(1)
> While Cells(rCount, 1).Formula <> ""
> tCell = Cells(rCount, 1).Formula
> With ActiveDocument
> Selection.InsertFile FileName:=tCell, Range:="", _
> ConfirmConversions:=False, _
> Link:=False, Attachment:=False
> End With
> rCount = rCount + 1
> Wend
> End With
> xlWB.Close False
> xlApp.Quit
> Set xlWB = Nothing
> Set xlApp = Nothing
> End Sub
>
> will read a list of documents from column 1 of "D:\My
> Documents\Test\ExcelWB.xls" and insert them in order into a new document.
> You can add the code to insert an appropriate TOC where you require it at
> the end of the macro e.g.
>
> With Selection
> .HomeKey Unit:=wdStory
> With .Fields
> .Add Selection.Range, wdFieldTOC, "\o ""1-3"" \h \z \u", False
> .Update
> End With
> .InsertBreak Type:=wdSectionBreakNextPage
> End With
> ActiveWindow.View.ShowFieldCodes = False
>
> ..
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
>
>
> John wrote:
> > Sorry, ment INCLUDETEXT
> >
> >
> > "John" wrote:
> >
> >> In Excel I have a list of file paths for a large number of word
> >> documents.
> >>
> >> What I would like to do is have the field INCLUDETEXT to look at the
> >> cells in excel and then insert the text to word.
> >>
> >> I would also like a table of contents to be created after they have
> >> been included.
> >>
> >> thanks for any help
> >>
> >> John
>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net