Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2024, 09:35 AM
Jakov93 Jakov93 is offline Remove hyphenation from copied text from pdf in Word VBA Windows 10 Remove hyphenation from copied text from pdf in Word VBA Office 2010
Advanced Beginner
Remove hyphenation from copied text from pdf in Word VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default 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
Thanks
Reply With Quote
  #2  
Old 03-20-2024, 12:50 PM
vivka vivka is offline Remove hyphenation from copied text from pdf in Word VBA Windows 7 64bit Remove hyphenation from copied text from pdf in Word VBA Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

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)
Or if you surely want to keep the character and remove dash + space, use:
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
Reply With Quote
  #3  
Old 03-20-2024, 12:56 PM
Jakov93 Jakov93 is offline Remove hyphenation from copied text from pdf in Word VBA Windows 10 Remove hyphenation from copied text from pdf in Word VBA Office 2010
Advanced Beginner
Remove hyphenation from copied text from pdf in Word VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
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
Thanks for reply,
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
Reply With Quote
  #4  
Old 03-20-2024, 01:11 PM
vivka vivka is offline Remove hyphenation from copied text from pdf in Word VBA Windows 7 64bit Remove hyphenation from copied text from pdf in Word VBA Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Your dash is Chr(30), so use:
Code:
 .text = Chr(30) & Chr(32)
 .MatchWildcards = True
Reply With Quote
  #5  
Old 03-20-2024, 01:20 PM
Jakov93 Jakov93 is offline Remove hyphenation from copied text from pdf in Word VBA Windows 10 Remove hyphenation from copied text from pdf in Word VBA Office 2010
Advanced Beginner
Remove hyphenation from copied text from pdf in Word VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

Dear vivka,
Also no change
Reply With Quote
  #6  
Old 03-20-2024, 01:30 PM
vivka vivka is offline Remove hyphenation from copied text from pdf in Word VBA Windows 7 64bit Remove hyphenation from copied text from pdf in Word VBA Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

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
Reply With Quote
  #7  
Old 03-20-2024, 02:01 PM
Jakov93 Jakov93 is offline Remove hyphenation from copied text from pdf in Word VBA Windows 10 Remove hyphenation from copied text from pdf in Word VBA Office 2010
Advanced Beginner
Remove hyphenation from copied text from pdf in Word VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

Also no change, I have been shocked
Try my file please Demo.docx
Reply With Quote
  #8  
Old 03-20-2024, 02:17 PM
vivka vivka is offline Remove hyphenation from copied text from pdf in Word VBA Windows 7 64bit Remove hyphenation from copied text from pdf in Word VBA Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

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.
Reply With Quote
  #9  
Old 03-20-2024, 02:21 PM
Jakov93 Jakov93 is offline Remove hyphenation from copied text from pdf in Word VBA Windows 10 Remove hyphenation from copied text from pdf in Word VBA Office 2010
Advanced Beginner
Remove hyphenation from copied text from pdf in Word VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

I'm sorry for being annoying
the result:
withithNO‑producincelanthosibystande cells35ImiceNiconsidereessentiafocontrollinLeishma niaaiNOS‑deficienmicarsusceptibltiNO(NOS2ilesionop atientwitcutaneouleishmaniasicomparewitnormaskin
Reply With Quote
  #10  
Old 03-20-2024, 02:31 PM
vivka vivka is offline Remove hyphenation from copied text from pdf in Word VBA Windows 7 64bit Remove hyphenation from copied text from pdf in Word VBA Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

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.
Reply With Quote
  #11  
Old 03-20-2024, 02:47 PM
vivka vivka is offline Remove hyphenation from copied text from pdf in Word VBA Windows 7 64bit Remove hyphenation from copied text from pdf in Word VBA Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

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.
Reply With Quote
  #12  
Old 03-20-2024, 07:06 PM
Jakov93 Jakov93 is offline Remove hyphenation from copied text from pdf in Word VBA Windows 10 Remove hyphenation from copied text from pdf in Word VBA Office 2010
Advanced Beginner
Remove hyphenation from copied text from pdf in Word VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

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
Reply With Quote
  #13  
Old 03-20-2024, 09:48 PM
Guessed's Avatar
Guessed Guessed is offline Remove hyphenation from copied text from pdf in Word VBA Windows 10 Remove hyphenation from copied text from pdf in Word VBA Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #14  
Old 03-20-2024, 09:53 PM
Jakov93 Jakov93 is offline Remove hyphenation from copied text from pdf in Word VBA Windows 10 Remove hyphenation from copied text from pdf in Word VBA Office 2010
Advanced Beginner
Remove hyphenation from copied text from pdf in Word VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

Thanks so much Andrew
It works perfectly
You are the hard task man
Thanks again
Reply With Quote
  #15  
Old 03-20-2024, 10:53 PM
vivka vivka is offline Remove hyphenation from copied text from pdf in Word VBA Windows 7 64bit Remove hyphenation from copied text from pdf in Word VBA Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Sure! I used Asc(ch) instead of AscW(ch). Live and learn.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
word hyphenation rogiburn Word 3 05-12-2021 10:24 AM
Remove hyphenation from copied text from pdf in Word VBA How do I remove [enter]s in copied doc? technofleep Word 7 06-28-2016 04:39 PM
Remove hyphenation from copied text from pdf in Word VBA Word 2003 Brackets appear around copied text barrage Word 1 12-16-2015 02:59 PM
Remove hyphenation from copied text from pdf in Word VBA 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft