Sign in to follow this  
Followers 0
saywell

Another Word UDF question!

6 posts in this topic

#1 ·  Posted (edited)

I'm replacing various bits of text with strings from my script.

All work except for 2 cases in a text box (address header needed to keep right justified stuff in header as well as left-justified main text].

According to the help, _WordDocFindReplace range defaults to searching the whole document:

$v_SearchRange | 0 = (Default) Specifies the entire document

Any range object

[edit] It works with tables, so I'll try using them rather than text box!

But this isn't working for me. Am I doing something wrong, or is this a limitation of the UDF? Is there another way to do this? My VBA skills are rudimentary - as in my other recent query - so not keen on tackling multi-line VBAs!

thanks,

William

Edited by saywell

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Textboxes are hidden in the fields collection.

One solution is to run the search two times: Once for the text and a second time for the fields.

Maybe this link helps.

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

Textboxes are hidden in the fields collection.

One solution is to run the search two times: Once for the text and a second time for the fields.

Maybe this link helps.

Thanks, water.

That's a bit beyond my present knowledge, but I'll have a good read of your links.

For now, I've put the text box contents in a table, instead (it was just a document header, needing the S&R to add the correct extension and email address according to its creator).

Regards,

William

Share this post


Link to post
Share on other sites

Sorry to be back here so soon, but I've discovered some odd behaviour in the _WordDocFindReplace function in my script.

I'm replacing CCCC in my new document with $ClinicCode, where the clinic code is in the format [3letters]/[3digits].

If I use 999 as the 3 digits - eg ABC/999 the search and replace puts 069 in the document!

It does this even if I replace the string in the command with "ABC/999" so it's not a string error. And it works fine for other numbers with 3 repeated digits.

However, if I use n99 it puts in n06 [where n is another digit]. Though nn9 renders correctly.

If I do a manual S&R in word, it works as expected, so it's not an odd word setting.

Is there a special useage of '99' in the word udf?

Any thoughts, anyone?

regards,

William

Share this post


Link to post
Share on other sites

Just tried it with Word 2002 and it works fine for me.

#include <word.au3>

$oWord = _WordCreate("C:\temp\test.doc")
$oDoc = _WordDocGetCollection($oWord, 0)
_WordDocFindReplace($oDoc,"CCCC","ABC/999")

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

Just tried it with Word 2002 and it works fine for me.

#include <word.au3>

$oWord = _WordCreate("C:\temp\test.doc")
$oDoc = _WordDocGetCollection($oWord, 0)
_WordDocFindReplace($oDoc,"CCCC","ABC/999")

Mine's 2002 too. And testing with a code snippet like yours works!

So, back to the code, and I see that my template has a '99' to be replaced by @MDAY - and today's the 6th, so @MDY = 06!!

How stupid can I get?

I've changed the 99 to XX so it's not changing the 99 that might appear in clinic code.

Regards,

William

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