#1
|
|||
|
|||
Remove hyphenation from copied text from pdf in Word VBA
Hi,
When I copy text from pdf, many hyphenation appear, I tried many search condition to look for "- " but all failed The only way which recognize that is when I type "^?‑ " So it require any character dash space Now I want to keep the character and remove dash space I used ^? again in replace box but it's not valid Any modification to such macro Code:
Sub RemoveDashSpace() Dim oRng As range If Len(Selection.range) = 0 Then MsgBox "Select the text first", vbCritical Exit Sub End If Set oRng = Selection.range With oRng.Find .ClearFormatting .Replacement.ClearFormatting .text = "" .Replacement.text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute Replace:=wdReplaceAll End With End Sub |
#2
|
|||
|
|||
Hi, Jakov93! There are several types of a dash: minus/hyphen (chr(45)), en-dash (chr(150)), and em-dash (chr(151). Try using each of them or alll of them at once with .MatchWildcards = True:
Code:
.text = "[" & Chr(45) & Chr(150) & Chr(151) & "]" & Chr(32) Code:
With oRng.Find .ClearFormatting .Replacement.ClearFormatting .text = "(?)- " .Replacement.text = "\1" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With |
#3
|
|||
|
|||
Quote:
vivka, no change occurs after applying the code try this within the NO‑producing cell and those in bystander cells35. In mice, NO is considered essential for con‑ trolling Leishmania, as iNOS‑deficient mice are sus‑ ceptible to iNOS (NOS2) in lesions of patients with cutaneous leish‑ maniasis compared with normal skin. Thanks |
#4
|
|||
|
|||
Your dash is Chr(30), so use:
Code:
.text = Chr(30) & Chr(32) .MatchWildcards = True |
#5
|
|||
|
|||
Dear vivka,
Also no change |
#6
|
|||
|
|||
Strange, because for me it works smoothly on your sample.
Try the full code: Code:
Sub RemoveDashSpace() Dim oRng As range If Len(selection.range) = 0 Then MsgBox "Select the text first", vbCritical Exit Sub End If Set oRng = selection.range With oRng.Find .ClearFormatting .Replacement.ClearFormatting .text = Chr(30) & Chr(32) .Replacement.text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End Sub |
#8
|
|||
|
|||
It's weird, but now your dash is Chr(63), which means it cannot be identified! This "dash" may be a graphical object (bitmap). I've come across such things: they look like normal characters, but can't be identified and manipulated with. I will try again tomorrow.
|
#9
|
|||
|
|||
I'm sorry for being annoying
the result: withithNO‑producincelanthosibystande cells35ImiceNiconsidereessentiafocontrollinLeishma niaaiNOS‑deficienmicarsusceptibltiNO(NOS2ilesionop atientwitcutaneouleishmaniasicomparewitnormaskin |
#10
|
|||
|
|||
Yes, I have the same result. Definitely, it's a bitmap image. Increase the font size and look, how it is selected (with blank sides/margins) and, if placed in Notepad, it is shown as a box.
|
#11
|
|||
|
|||
Finally, I've found a solution: Using plain Find-Replace, paste in FindWhat the copied "dash" plus space & replace all instances of them with nothing.
|
#12
|
|||
|
|||
Thanks so much vivka
I appreciate your time and efforts What is the magic secrete behind this condition that I can't use VBA macro with it? Thanks again |
#13
|
||||
|
||||
Try this version which works on your brief sample - it appears the dash is using the extended Ascii codes.
Code:
Sub Macro1() With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Text = ChrW(8209) & " " .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchKashida = False .MatchDiacritics = False .MatchAlefHamza = False .MatchControl = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#14
|
|||
|
|||
Thanks so much Andrew
It works perfectly You are the hard task man Thanks again |
#15
|
|||
|
|||
Sure! I used Asc(ch) instead of AscW(ch). Live and learn.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
word hyphenation | rogiburn | Word | 3 | 05-12-2021 10:24 AM |
How do I remove [enter]s in copied doc? | technofleep | Word | 7 | 06-28-2016 04:39 PM |
Word 2003 Brackets appear around copied text | barrage | Word | 1 | 12-16-2015 02:59 PM |
Finding and Replacing a word with text copied to clip board | spc94 | Word VBA | 3 | 06-25-2015 04:46 AM |
Copied shape/text box pastes as an image in Word | spectator | Word | 0 | 06-04-2014 08:45 AM |