Sign in to follow this  
Followers 0
Floppy

_Word_DocFindReplace with character

12 posts in this topic

#1 ·  Posted (edited)

Hello,

I'm trying to replace "%s1%" with a checkbox in a Word document. I thought I could use the font Wingdings2 to do this. (you can see here the character I would like to use: http://it.tinypic.com/r/10wqvx0/8)

The problem is if I copy and paste the character from the Character Map, SciTe displays a little square instead of the character. What should I put instead?

_Word_DocFindReplace($oDoc, "%s1%", "WHAT SHOULD I PUT HERE???")

Edited by Floppy

Share this post


Link to post
Share on other sites



After replacing %s1% you need to set the font for the replacing character to WingDings2.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

water, your solution is smart. But how can I change the font of all chackeboxes at once?

Share this post


Link to post
Share on other sites

Use a for loop to loop through each one and change the font?


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Exactly.

Use _Word_DocFind in  a loop to find all occurrences of "%s1%" and change the font. Then replace all "%s1%" with the checkbox character.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I tried with the following script from _Word_DocFind help file, but it underlines only the first occurance. Why?

Global $oRangeFound
$oRangeFound = _Word_DocFind($oDoc, "%s1%", 0)
MsgBox(0,@error,$oRangeFound)
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oRangeFound.Underline = True
While 1
    $oRangeFound = _Word_DocFind($oDoc, "%s1%", -1, $oRangeFound)
MsgBox(0,@error,$oRangeFound)
    If @error <> 0 Then ExitLoop
    $oRangeFound.Underline = True
WEnd

Share this post


Link to post
Share on other sites

Because you spcified -1 (Selection) as the range to be searched. Selection is the part of the document you have marked.

Try 0 instead.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I tried but it's the same: only the first occurrence gets underlined.

Share this post


Link to post
Share on other sites

Which version of Office do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Office 2013 x64 (os Windows 8.1 x64)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

This works fine for me and underlines all occurrences of "%s1%" in the document:

#include <Word.au3>
#include <MsgBoxConstants.au3>
Global $oRangeFound
Global $oWord = _Word_Create()
Global $oDoc = _Word_DocOpen($oWord, "C:\temp\test.docx")
$oRangeFound = _Word_DocFind($oDoc, "%s1%", 0)
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oRangeFound.Underline = True
While 1
    $oRangeFound = _Word_DocFind($oDoc, "%s1%", 0, $oRangeFound)
    If @error <> 0 Then ExitLoop
    $oRangeFound.Underline = True
WEnd
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

A played a little bit with Word and recorded a macro to insert the Wingdings2 symbols.

This script works fine on Windows 7, Office 2010:

#include <Word.au3>
#include <MsgBoxConstants.au3>
Global $oRangeFound
Global $oWord = _Word_Create()
Global $oDoc = _Word_DocOpen($oWord, "C:\temp\test.docx")
$oRangeFound = _Word_DocFind($oDoc, "%s1%", 0)
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oRangeFound.InsertSymbol(-4012, "Wingdings 2", True)
While 1
    ConsoleWrite("**" & @CRLF)
    $oRangeFound = _Word_DocFind($oDoc, "%s1%", 0, $oRangeFound)
    If @error <> 0 Then ExitLoop
    $oRangeFound.InsertSymbol(-4012, "Wingdings 2", True)
WEnd

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0