Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-04-2022, 08:22 PM
BrianHoard BrianHoard is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2019
Advanced Beginner
Pasting superScripts from Word problem
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default Pasting superScripts from Word problem

I have written a vba script that modifies superScript numbers in Word. I modify their color, and change the .Text as I renumber them.


After my script is run, editors then copy/paste from Word into a website rich text area. We're finding that superScripts that were created manually paste in fine. But the ones my script has modified paste in as normal size text.
is there some way to inspect what is different between the ones that work and the ones that don't?
They both look the same while in Word, so why some lose their superScript formatting during paste has me confused.

Last edited by BrianHoard; 08-04-2022 at 08:37 PM. Reason: Added example text
Reply With Quote
  #2  
Old 08-05-2022, 01:30 AM
Guessed's Avatar
Guessed Guessed is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

Can you post a sample document that shows both variants?

I'm guessing that one is assigned by a character style and the other is local formatting.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-05-2022, 04:34 AM
BrianHoard BrianHoard is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2019
Advanced Beginner
Pasting superScripts from Word problem
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Here's a sample. Both Test1 and Test2 have their numbers as superScript in Word.
I see the same problem when pasting from that into this rich text editor(but only during editing), the first one loses it's superScript formatting, but number 2 does not.


Please see the attached Word docx file, and .png screenshot
Attached Images
File Type: png snap.png (24.9 KB, 17 views)
Attached Files
File Type: docx superscriptPasteTest.docx (14.8 KB, 8 views)
Reply With Quote
  #4  
Old 08-05-2022, 04:31 PM
Guessed's Avatar
Guessed Guessed is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

As predicted, one has a character style applied to it (Endnote Reference), the two is formatted with a direct local font setting. If your Rich Text editor only honours the direct formatting then you will need to convert those formatted with the Endnote style
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 08-05-2022, 06:44 PM
BrianHoard BrianHoard is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2019
Advanced Beginner
Pasting superScripts from Word problem
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Thanks Andrew, I'll give that a try. These superScripts that I'm messing with did originally start out as endnote markers, which were deleted and replaced with my number. But apparently the original formatting was kept.
Reply With Quote
  #6  
Old 08-06-2022, 07:29 AM
BrianHoard BrianHoard is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2019
Advanced Beginner
Pasting superScripts from Word problem
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Okay, I'm now trying to find how to fix this character formatting and stuck again. Here is the portion of my script where I'm replacing what once was an endnote marker/citation number with my superScript number. So how to fix this endnote reference character formatting while keeping the superScript? I've commented out a couple attempts that aren't working. These do remove the endnote reference character style, but show as regular size text when pasted. They look fine in Word still.



Code:
' Write Citation number
With rng_sourcesCited
  .Collapse Direction:=wdCollapseEnd
  .InsertAfter txt_citationNumber
  
  ' How to remove the endnote reference character style?
  ' .Style = wdStyleNormal ' These lose superScript formatting
  ' .CharacterStyle = wdStyleNormal
  
  .Font.Superscript = True ' Make this text superScript
  .Font.Bold = False ' Ensure the superScript doesn't inherit boldness
End With
Reply With Quote
  #7  
Old 08-07-2022, 02:17 AM
Guessed's Avatar
Guessed Guessed is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

Does this work? Make sure you test the result after pasting into your rich text editor
Code:
Sub Macro2()
  With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .ClearFormatting
    .Style = ActiveDocument.Styles("Endnote Reference")
    .Replacement.ClearFormatting
    .Replacement.Font.Superscript = True
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 08-07-2022, 06:21 AM
BrianHoard BrianHoard is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2019
Advanced Beginner
Pasting superScripts from Word problem
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Thanks Andrew, however this script doesn't seem to change the formatting. Still getting the same result when pasted. Running the following code to inspecting the style on each character after running your code shows as below. Not sure how to get rid of these pesky Endnote References

Code:
Sub formatCheck()
  Dim rng_character As Range
  For Each rng_character In ActiveDocument.Characters
    Debug.Print (rng_character.Text & " " & rng_character.Style)
  Next rng_character
End Sub
T Normal
e Normal
s Normal
t Normal
1 Endnote Reference
Normal
T Normal
e Normal
s Normal
t Normal
2 Endnote Reference
Reply With Quote
  #9  
Old 08-07-2022, 09:35 AM
BrianHoard BrianHoard is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2019
Advanced Beginner
Pasting superScripts from Word problem
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

I think I've got it worked out. I saw mention on another forum from 2021 (sorry, didn't save the link) that there is a bug in Word when trying to modify character styles through a find. Of course, since this has to process every character in the document, is too slow to use on large docs. I'll continue to work on this so I don't have to check every character individually.
So I did this and it fixed it. The previous Endnote Reference is now Normal.
Code:
Sub test()
  ' Remove Endnote Reference character style
  
  Dim rngDoc As Range
  Dim rngChar As Range
  
  Set rngDoc = ActiveDocument.Range
  
  For Each rngChar In rngDoc.Characters
    If rngChar.Style = "Endnote Reference" Then
      rngChar.Font.Reset
      rngChar.Font.Superscript = True
     End If 'rngChar.Style
  Next rngChar

  For Each rngChar In ActiveDocument.Range.Characters
    Debug.Print (rngChar.Text & ", " & rngChar.Style)
  Next rngChar
End Sub
Result:
T, Normal
e, Normal
s, Normal
t, Normal
1, Normal
Pastes as superScript into website's rich text editor.
Reply With Quote
  #10  
Old 08-07-2022, 01:44 PM
BrianHoard BrianHoard is offline Pasting superScripts from Word problem Windows 10 Pasting superScripts from Word problem Office 2019
Advanced Beginner
Pasting superScripts from Word problem
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Okay Andrew, from your previous help on a different question, I managed to get these Endnote References removed by doing a Do While after the find. Just tested this on a 285 page document with 15 instances, and it finished in just 5 seconds. Text pastes into Rich Text Editors fine now. Whew, this was a tough one!
Code:
' Remove Endnote Reference style from superScript numbers
Dim rngCheck As Range
Dim rngChar As Range

With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    .Forward = True
    .Font.Superscript = True ' Finds only superScripts
    .Wrap = wdFindStop
    .MatchWildcards = True ' Allows regex for .Text
    .Text = "[0-9]{1,}" ' Finds only numbers, 1 or more
    .Replacement.Text = ""
  End With
  
  Do While .Find.Execute = True ' When we get a hit, do this
    For Each rngChar In .Characters
      If rngChar.Style = "Endnote Reference" Then
        rngChar.Font.Reset ' Remove the Endnote Reference character style
        rngChar.Font.Superscript = True
      End If 'rngChar.Style
    Next rngChar
    .Collapse wdCollapseEnd
  Loop
End With 'ActiveDocument.Range
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with copying/pasting from web to word 2016 cricket1001 Word 2 07-20-2020 07:00 PM
Pasting superScripts from Word problem Extract words which has superscripts and the corresponding superscript value in footnotes in word sai Word VBA 12 05-11-2020 04:29 AM
Problem pasting mixed content from webpage into Word 2007 silverman166 Word 0 02-17-2020 03:46 AM
Word 2000--Problem with format retention when pasting JerryL Word 2 01-05-2014 07:20 PM
Copy and pasting problem Word 2010 Sarah262 Word 3 08-16-2012 03:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:36 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