Apologies if this the wrong list for this question, if so could someone point me in the right direction!
I am trying to generate an script to process multiple CSV's into a single excel doc, create tables and then create a shell report document template. I have managed all this so far but cannot seem to add a TOC. From what I can tell I have translated the VBA command correctly. Ideally I would like to add it at the start of the document, however I also cannot move the selector position & have been trying to just insert a TOC anywhere as a first step. $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application'); my $document = $Word->Documents->Add; foreach my $file (getFileListAsArray($basedir,"\.(?:gif|GIF)\$")){ print "Adding $file to document\n"; $name=$file; $name=~s/$striphead//; $name=~s/$striptail//; $document->ActiveWindow->Selection -> {Style} = "Heading 1"; $document->ActiveWindow->Selection -> TypeText("$name\n"); $document->ActiveWindow->Selection -> {Style} = "Normal"; $document->ActiveWindow->Selection -> TypeText("Type Text here 1\n"); $Word->Selection->InlineShapes->AddPicture({ FileName => "$basedir\\$file", LinkToFile => "False", SaveWithDocument => "True"}); $document->ActiveWindow->Selection -> TypeText("Type Text here 2\n"); $Word->Selection->InsertBreak({Type=>wdSectionBreakNextPage}); } $Range = $Word->Selection->{'Range'}; $Word->ActiveDocument->TablesOfContents->Add ({ Range=>$Range, RightAlignPageNumbers=>"True", UseHeadingStyles=>"True", UpperHeadingLevel=>"1", LowerHeadingLevel=>"4", IncludePageNumbers=>"True", AddedStyles=>"", UseHyperlinks=>"True", HidePageNumbersInWeb=>"True", UseOutlineLevels=>"True" }); $document ->SaveAs( $outfile ); $document ->Close; Im using Word 2007 many thanks.