This is a continuation of yesterdays Perl, Word and wingding question. However, I have started a new thread since I think a new set of questions arise.
I want to insert wingding symbols in existing documents. So far this has failed mainly because of difficulties with the ‘number’ associated with these in Word.
Therefore I have tried a new approach which uses the InsertSymbol method.
The idea is that I use search to get to the correct place in the document, use InsertSymbol to add the wingding symbol and finally remove the text used in the search.
To get the VBA code, I recorded a macro in Word which inserted a symbol. This gave
Selection.insertsymbol Font:="Wingdings", CharacterNumber:=-4063, Unic +ode :=True
I then added this to Perl code given some time ago by polypompholyx after changing it using the ‘rules’ in the same reply. This gave
use Win32::OLE; use Win32::OLE::Const "Microsoft Word 12.0 Object Library"; use Win32::OLE::Const "Microsoft Office 12.0 Object Library"; my $word = Win32::OLE->new( 'Word.Application', 'Quit' ) or die "Can't create Word OLE: " . Win32::OLE->LastError . "\n"; $word->{'Visible'} = 1; my $doc = $word->Documents->Add or die "Can't create new Word documen +t: " . Win32::OLE->LastError . "\n"; my $selection = $word->Selection; # select current position $selection->{'Style'} = 'Title'; $selection->TypeText( 'Document title' ); $selection->TypeParagraph; $selection->{'Style'} = 'Normal'; $selection->TypeText( 'Lorum ipsum' ); $selection->TypeParagraph; # new line $selection->insertsymbol ( Font=> "Wingdings", CharacterNumber => -406 +3, Unicode => 'True'); $word-> ActiveDocument->SaveAs('c:\tmp\foo.doc'); #$doc->SaveAs( 'foo.docx' ); $word->Quit;
The original set of Perl lines worked and added the text etc. Sadly the InsertSymbol line failed.
Can any wiser Monk than I explain what to do?

In reply to 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.