![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Hi Everyone,
I am new to vba. I need to extract the words which have superscripts from the main document part and the corresponding superscript value in footnotes. For example : Main Doc has : Doctor^1 Footnotes has : 1. Sample Citation I need to extract something like this into excel Doctor, 1, Sample Citation Any help is much appreciated. Thanks |
|
#2
|
||||
|
||||
|
Extracting a single word preceding a footnote seems fairly meaningless, as footnotes typically relate to rather more than just the last preceding word. A simple way of copying all footnotes without code is to open any footnote, then press Ctrl-A, Copy. You can then paste them into Excel and use the text-to-columns function to split the footnote references from the content.
PS: Kindly post Word VBA questions in the Word VBA forum. You post does not concern 'Forum Support'. I have moved the thread to the correct forum.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Hi
I think you did not get my point. Example : Lets say I have a sentence like : he is good^1 ( 1 is the superscript and if I double click on 1 it will navigate to the first footnotes) in the word document So I would like to extract the word "good"(which has superscript) and the superscript value(i.e. 1) . Thank you. |
|
#4
|
||||
|
||||
|
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
||||
|
||||
|
What you're getting is what you specified in post 1:
Quote:
Quote:
So how is the macro to know when you want one word only, or multiple words?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#6
|
|||
|
|||
|
Is there a chance to extract multiple words?
|
|
#7
|
|||
|
|||
|
No word vba for this task?
|
|
#8
|
||||
|
||||
|
Try:
Code:
Sub ExportFootnotes()
Dim Rng As Range, StrOut As String, StrTmp As String, i As Long, j As Long, xlApp As Object, xlWkBk As Object
StrOut = "Reference,Footnote #,Footnote Text"
StrOut = Replace(StrOut, ",", vbTab)
With ActiveDocument
' Process the Footnotes
For i = 1 To .Footnotes.Count
With .Footnotes(i)
Set Rng = .Reference.Words.First.Previous.Words.First
With Rng
Do While .Words.First.Previous.Font.Italic = True
.Start = .Words.First.Previous.Words.First.Start
Loop
If InStr(.Text, " v ") = 0 Then .Start = .Words.Last.Start
End With
StrOut = StrOut & vbCr & Rng.Text & vbTab & _
i & vbTab & Replace(Replace(.Range.Text, vbTab, "<TAB>"), vbCr, "<P>")
End With
Next
End With
' Test whether Excel is already running.
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
'Start Excel if it isn't running
If xlApp Is Nothing Then
Set xlApp = CreateObject("Excel.Application")
If xlApp Is Nothing Then
MsgBox "Can't start Excel.", vbExclamation
Exit Sub
End If
End If
On Error GoTo 0
With xlApp
Set xlWkBk = .Workbooks.Add
' Update the workbook.
With xlWkBk.Worksheets(1)
For i = 0 To UBound(Split(StrOut, vbCr))
StrTmp = Split(StrOut, vbCr)(i)
For j = 0 To UBound(Split(StrTmp, vbTab))
.Cells(i + 1, j + 1).Value = Split(StrTmp, vbTab)(j)
Next
Next
.Columns("A:C").AutoFit
End With
' Tell the user we're done.
MsgBox "Done.", vbOKOnly
' Switch to the Excel workbook
.Visible = True
End With
' Release object memory
Set xlWkBk = Nothing: Set xlApp = Nothing
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#9
|
|||
|
|||
|
Thank you for the quick response. Below code is extracting the last word which has superscript.
StrOut = StrOut & vbCr & .Reference.Words.First.Previous.Words.First & vbTab & _ i & vbTab & Replace(Replace(.Range.Text, vbTab, "<TAB>"), vbCr, "<P>") Is there a way I could extract the entire case name like I have attached in the screenshot. output like : Kruger v Coetzee (Full Case Name) |
|
#10
|
||||
|
||||
|
Yes, but you have to say what the rules are in a way a macro can identify how many words to get. Macros don't know what case names are, for example.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#11
|
|||
|
|||
|
The rule would be : need to extract case name which are in italic with the text " v " included.
|
|
#12
|
||||
|
||||
|
Try the revised code in post 6.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#13
|
|||
|
|||
|
Thank a ton.
This looks good. |
|
| Tags |
| extract superscript word |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to change superscript footnotes into genuine Word footnotes
|
Knounte29 | Word VBA | 41 | 01-16-2020 04:48 PM |
Help with Footnotes! Superscript and Numbering Issues
|
Mitavec | Word | 13 | 10-21-2018 01:37 PM |
turn footnotes and their respective superscripts into normal text
|
GEORGEJUNGCOCAINE | Word VBA | 2 | 02-27-2018 10:01 PM |
| turn footnotes and their respective superscripts into normal unlinkable text | GEORGEJUNGCOCAINE | Word | 1 | 02-27-2018 05:47 PM |
| Footnotes/Citations not superscript | wordquery | Word | 3 | 04-12-2017 01:55 PM |