Jump to content

Word, change font for specific parts of a word document


Recommended Posts

Posted

Hi all,

i am trying to create a script, that replaces a placeholder text with numbers counting up in an existing word document. the doc multiple cells with the same placeholders twice in each cell. this works fine

 my code:

#include <Word.au3>
$WordObject=_Word_Create ()
$WordDocObject=_Word_DocOpen ($WordObject, "AveryMuster.doc")
$i = 0
$beginn = 3380001
While $i <= 51
_Word_DocFindReplace($WordDocObject, "platz", $beginn + $i, 1)
_Word_DocFindReplace($WordDocObject, "platz", $beginn + $i, 1)
$i =$i+1
WEnd

the doc

grafik.png.ea350b03471bf4f18fe9877e4882b980.png

 

grafik.png

Posted

(posted to soon, here is the rest)

what it does :

grafik.png.2b850aa5681a31529c66932514d9a4e5.png

 

after changing the placeholder to the specified number i want to change the upper line in each cell to a barcode-font (code 39), which i am having problems with. if i change the upper text in each cell to the barcode font beforehand, the script cant read it and starts the replacing with the second line in the first cell

what it does if i change the font beforehand:

grafik.png.507b97699db858cd05ba7136ed1f8c7b.png

i tried fiddeling around with "$sFontName = ..." but cant get it to do what i want

what i want (when scanning the barcode it reads the number below the barcode):

grafik.png.b1740c4f78b40d2cc4ba634db916cf09.png

if you are wondering the doc is a form for stickers, i hope you can understand what i want :D

any ideas?

grafik.png

Posted

Please post the code you run.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted
#include <Word.au3>
$WordObject=_Word_Create ()
$WordDocObject=_Word_DocOpen ($WordObject, "AveryMuster.doc")
$i = 0
$beginn = 3380001
While $i <= 51
_Word_DocFindReplace($WordDocObject, "platz", $beginn + $i, 1)
_Word_DocFindReplace($WordDocObject, "platz", $beginn + $i, 1)
$i =$i+1
WEnd
Posted

Sorry, I missed the code you already posted in #1.

I suggest to replace _Word_DocFindReplace  with _Word_DocFind. _Word_DocFind returns the range of the found placeholder. You then can change the placeholder to your number and set the font of the range.
Something like (untested):

While $i <= 51
    ; Replace/format first placeholder
    $oRange = _Word_DocFind($WordDocObject, "platz", $beginn + $i, 1)
    $oRange.Text = $beginn + $i
    $oRange.Font.Name = "FontName" ; needs to be changed by you
    $oRange.Font.Size = 12         ; needs to be changed by you
    ; Replace second placeholder
    _Word_DocFindReplace($WordDocObject, "platz", $beginn + $i, 1)
    $i =$i+1
WEnd

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...