Microsoft Office Forums Macro Help Swapping HTML Code

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2019, 12:21 PM
pclark2 pclark2 is offline Macro Help Swapping HTML Code Windows 7 64bit Macro Help Swapping HTML Code Office 2019
Novice
Macro Help Swapping HTML Code
 
Join Date: Feb 2019
Posts: 1
pclark2 is on a distinguished road
Default Macro Help Swapping HTML Code

I have never worked with macros before so don't really understand the coding. I'm trying to get a macro that takes footnotes and converts them to regular text that can then easily be copied and pasted into our website editor. I have found some create macros out there that do almost all of this, but the superscript numbers have a weird span on them instead of the correct <sup> code. I'm struggling to find something that corrects that.

So currently when you look at the HTML Word is generating you get:


HTML Code:
<span class=MsoEndnoteReference>1</span>
You should just get:
HTML Code:
<sup>1</sup>
Here is the macro I have thus far with bits I've found online. It first converts footnotes to endnotes and changes it to use numbers instead of Roman numerals. Then it changes them all to regular text. Lastly it removes bookmark links. The only piece of the puzzle I'm missing is making those spans superscripts.
Code:
Sub CleanNotes()

ActiveDocument.Footnotes.Convert
    With ActiveDocument.Range(Start:=ActiveDocument.Content.Start, End:= _
        ActiveDocument.Content.End).EndnoteOptions
        .Location = wdEndOfDocument
        .NumberingRule = wdRestartContinuous
        .StartingNumber = 1
        .NumberStyle = wdNoteNumberStyleArabic
    End With

Application.ScreenUpdating = False
Dim nRng As Range, eNote As Endnote, nRef As String
With ActiveDocument
  For Each eNote In .Endnotes
    With eNote
      With .Reference.Characters.First
        .Collapse wdCollapseStart
        .InsertCrossReference wdRefTypeEndnote, wdEndnoteNumberFormatted, eNote.Index
        nRef = .Characters.First.Fields(1).Result
        .Characters.First.Fields(1).Unlink
      End With
      .Range.Cut
    End With
    If .Range.EndnoteOptions.Location = wdEndOfSection Then
      Set nRng = eNote.Range.Sections.First.Range
    Else
      Set nRng = .Range
    End If
    With nRng
      .Collapse wdCollapseEnd
      .End = .End - 1
      If .Characters.Last <> Chr(12) Then .InsertAfter vbCr
      .InsertAfter nRef & " "
      With .Paragraphs.Last.Range
        .Style = "Endnote Text"
        .Words.First.Style = "Endnote Reference"
      End With
      .Collapse wdCollapseEnd
      .Paste
      If .Characters.Last = Chr(12) Then .InsertAfter vbCr
    End With
  Next
  For Each eNote In .Endnotes
    eNote.Delete
  Next
End With
Set nRng = Nothing
Application.ScreenUpdating = True

Dim bkm As Bookmark
For Each bkm In ActiveDocument.Bookmarks
bkm.Delete
Next bkm

End Sub
Thank you!
Reply With Quote
  #2  
Old 02-11-2019, 02:27 PM
macropod's Avatar
macropod macropod is offline Macro Help Swapping HTML Code Windows 7 64bit Macro Help Swapping HTML Code Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,533
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

See the 'UnLinkNotes' macro in: https://www.msofficeforums.com/word/...html#post35017. With the code there, all you need do is change the .InsertAfter & .InsertBefore strings, doing something similar to the references in the footnotes, too, if you wish.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 02-11-2019, 03:25 PM
macropod's Avatar
macropod macropod is offline Macro Help Swapping HTML Code Windows 7 64bit Macro Help Swapping HTML Code Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,533
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Cross-posted at: https://stackoverflow.com/questions/...cing-some-html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swapping column and row formats. Letters to numbers etc. AdamNT69 Excel 2 10-17-2016 08:44 AM
Macro Help Swapping HTML Code VBA Macro code help get4hari Excel Programming 8 09-26-2015 10:33 PM
Search and replace/insert HTML code into Master File using tags dave8555 Excel 2 02-23-2014 03:51 PM
Strange HTML code inside an e-mail Joostdegrote Outlook 0 09-13-2010 07:57 AM
Can you actually write HTML and CSS in a word document and send it as an html page jackaroo Word 0 07-12-2010 07:49 AM


All times are GMT -7. The time now is 08:30 AM.


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