Thank you for everyone’s suggestions. I have looked at the various references and also ‘googled' for a solution.
Frustratingly I found places where the insertion point was mentioned and even questions about how to ‘set’ it
but no answers using either VBA or Perl code.
Therefore I used the recording macro facility with Word to locate a character hoping that this would give a clue about what to do. This gave the following
Selection.Find.ClearFormatting With Selection.Find .Text = "!" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.MoveRight Unit:=wdCharacter, Count:=1 Application.Run MacroName:="Normal.NewMacros.insertsymbol"
I was not really sure what to do but I did make an attempt and included it in another Perl test.
I ignored the last line and simply used what I knew should work to add a wingding character. The code is below
use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; # set $filepath to the full path to the direcotry where the file to be + changed, test.doc, is stored my $filepath = 'C:\tmp'; my $oldfile = $filepath . '\wingding1.doc'; my $newfile = $filepath . '\wingding1-edit.doc'; my $word = Win32::OLE-> GetActiveObject('Word.Application') || Win32::OLE-> new('Word.Application','Quit'); my $doc = $word-> Documents->Open("$oldfile"); # is application visible 0=no 1=yes $word-> {visible} = 0; my $selection = $word->Selection; # select current position # start of Word macro conversion $selection->Find->ClearFormatting; $selection->Find ( Text => "!", ReplacementText => "", Forward => 1, Wrap => wdFindContinue, Format => 0, MatchCase => 0, MatchWholeWord => 0, MatchWildcards => 0, MatchSoundsLike => 0, MatchAllWordForms => 0); $selection->Find->Execute; $selection->MoveRight ( Unit => wdCharacter, Count => 1); $selection->InsertSymbol( { Font=> "Wingdings", CharacterNumber => -40 +63, Unicode => 1 }); # save word file $word-> ActiveDocument->SaveAs($newfile); # close word file $doc-> Close(); $word-> Quit();
I used this with a document with a ! towards the end of the first line. Sadly this still put the inserted
wingding at the beginning of the document. I even tried with just Text => "!" in the ->Find
(partly because I was not at all sure that Replacement.Text should be converted as
ReplacementText) but this also did not work.
Has any Monk an idea how to make this work?

In reply to Re^4: InsertSymbol usage to modify Word document by merrymonk
in thread InsertSymbol usage to modify Word document by merrymonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.