UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Find/replace "unknown" Characters (word 2016), Any Version    
 
   
doctor9
post Apr 6 2018, 02:41 PM
Post#1


UtterAccess Editor
Posts: 18,324
Joined: 29-March 05
From: Wisconsin


So, I've been tasked with converting some PDF files into Word files so they can be customized to our company. It's a long technical document, and I'm trying to write macros to speed up the process. First, I take the PDF and use Save As->Rich Text to create a document that's about 95% ready to go. The issue I'm trying to fix is the one seen in the attached screenshot. The text in the middle line should read:

(b) Mixture placed in a 140ºF (60ºC) oven for 16 ± 1 hour for curing?

So, I thought I could create a simple macro to do a search/replace. The little "box" character is CHR(63) according to the Immediate Window, for both the degree symbol AND the plus/minus symbol. But I can't seem to use the built-in Find to find this particular character. Here's what I'm trying:

CODE
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = Chr(63) & "C"
        .Replacement.Text = "°C"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll


Even when it's stripped down to just the FIND bit, and ignoring the trailing "C", it just can't find any of the instances - and there are a LOT of them. Right now I'm using copy/paste to replace them all manually, and it's just a huge waste of my time.

Any suggestions?

Dennis
Attached File(s)
Attached File  Unknown_Characters_in_Word.jpg ( 30.67K )Number of downloads: 3
 

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
cheekybuddha
post Apr 6 2018, 04:17 PM
Post#2


UtterAccess VIP
Posts: 10,257
Joined: 6-December 03
From: Telegraph Hill


Hi Dennis,

Check the string using AscW() instead of Asc().

It will be a unicode character that can affect character spacing.

See this thread

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
doctor9
post Apr 6 2018, 04:24 PM
Post#3


UtterAccess Editor
Posts: 18,324
Joined: 29-March 05
From: Wisconsin


David,

I selected one of the boxes and entered this in the Immediate Window:

CODE
? ascw(selection.Text)
-3920


Is it me, or is a negative value concerning? I tried this...
CODE
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = AscW(-3920) & "C"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute

...and it couldn't find anything. The cursor just stays put. (If I just search for "C", it works, so I don't think it's a syntax issue.)

Dennis

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
cheekybuddha
post Apr 6 2018, 04:26 PM
Post#4


UtterAccess VIP
Posts: 10,257
Joined: 6-December 03
From: Telegraph Hill


https://unicode-table.com/en/search/?q=-3920

Don't know whether this is helpful!!

--------------------


Regards,

David Marten
Go to the top of the page
 
doctor9
post Apr 6 2018, 04:28 PM
Post#5


UtterAccess Editor
Posts: 18,324
Joined: 29-March 05
From: Wisconsin


David,

Thanks. I'm just trying to get Word VBA to successfully FIND the darned character so I can do a replace. If I can't get a successful FIND, I can't do the Replace. Right now, Word is acting dumb, i.e. "Uuh, I can't find any characters like that in this document!"

Dennis

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
cheekybuddha
post Apr 6 2018, 04:29 PM
Post#6


UtterAccess VIP
Posts: 10,257
Joined: 6-December 03
From: Telegraph Hill


CODE
' ...
    With Selection.Find
        .Text = ChrW(-3920) & "C"
' ...

--------------------


Regards,

David Marten
Go to the top of the page
 
doctor9
post Apr 9 2018, 08:18 AM
Post#7


UtterAccess Editor
Posts: 18,324
Joined: 29-March 05
From: Wisconsin


David,

Ah, thank you for your patience. That seems to be working!

Dennis

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
cheekybuddha
post Apr 9 2018, 09:54 AM
Post#8


UtterAccess VIP
Posts: 10,257
Joined: 6-December 03
From: Telegraph Hill


I think this sort of problem will become more commonplace as Unicode becomes more ubiquitous.

Plain old Asc() and Chr() won't cut it anymore! Now we have to handle emojis too! pullhair.gif

Glad it's working for you! thumbup.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
zaxbat
post Apr 9 2018, 10:10 AM
Post#9



Posts: 1,180
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


LOL but you're absolutely right

--------------------
Kindest regards, and Cheers!
ZAX

A picture is worth a thousand words and a zipped DB is worth a thousand pictures.
Oh, and....please don't disappear into the Twilight Zone.... Holler back with your results!
Go to the top of the page
 
doctor9
post Apr 10 2018, 10:22 AM
Post#10


UtterAccess Editor
Posts: 18,324
Joined: 29-March 05
From: Wisconsin


> Now we have to handle emojis too!

Ugh. I was hoping I could retire before something like this. giveup.gif

Dennis

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
cheekybuddha
post Apr 10 2018, 11:51 AM
Post#11


UtterAccess VIP
Posts: 10,257
Joined: 6-December 03
From: Telegraph Hill


dance.gif tongue.gif ohyeah.gif

--------------------


Regards,

David Marten
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    15th August 2018 - 11:31 AM