Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 11-19-2012, 04:20 AM
franklekens franklekens is offline Macro to convert text to endnote? Windows XP Macro to convert text to endnote? Office 2003
Novice
 
Join Date: Jul 2010
Posts: 29
franklekens is on a distinguished road
Default

If I may come back to this old topic: I'm trying it out right now. I'm looking for a more specific string of text.
But when I try to execute the macro, it gives me an error 5560, and error detection (or whatever it's called in English) highlights this line for me:
Do While .Execute = True

What could be wrong with that?

I've modified the macro to look like this, to search for the texts I'd like to change into endnotes (i.e. texts like [EINDNOOT 1], where only the figure ever changes.

(I'd really appreciate any help -- it's to get Word to fix a faulty manual notation for endnotes, where both me and the source text of my translation made some errors in the numbering. I hope converting the manual notations to real Word endnotes will fix the numbering. I can always convert back to plain text if need be -- I hope.)



Quote:
Sub MakeEndNotes()
Dim RngSel As Range, RngFnd As Range, StrNote As String
Application.ScreenUpdating = False
With Selection
Set RngSel = .Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
.Text = "\[EINDNOOT [0-9]{1;3}(\]"
Do While .Execute = True
Set RngFnd = ActiveDocument.Range(Start:=Selection.Start, End:=Selection.End)
StrNote = Mid(RngFnd.Text, 2, Len(RngFnd.Text) - 2)
ActiveDocument.Endnotes.Add RngFnd, , StrNote
RngFnd.Text = vbNullString
Loop
End With
End With
RngSel.Select
Set RngFnd = Nothing: Set RngSel = Nothing
Application.ScreenUpdating = True
End Sub
Oh, and quick question: does this macro create endnotes numbered 1,2,3, &c? Because that's really what I need.
(I can do some stuff with search and replace and macros, but I don't know enough about Word's macro language to understand all of the codes in this macro.)
Reply With Quote
  #17  
Old 11-19-2012, 02:05 PM
macropod's Avatar
macropod macropod is offline Macro to convert text to endnote? Windows 7 64bit Macro to convert text to endnote? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your Find expression is malformed, instead of:
"\[EINDNOOT [0-9]{1;3}(\]"
you should have:
"\[EINDNOOT [0-9]{1;3}\]"
or
"\[EINDNOOT [0-9]{1;3}(\])"
Even then, however, the code won't work as the MID expression (in Mid(RngFnd.Text, 2, Len(RngFnd.Text) - 2)) would need to be modified to take account of your additional text.

There is a more sophisticated version of the macro, that can deal with your [EINDNOOT #] format, here: http://gregmaxey.com/word_tip_pages/...footnotes.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #18  
Old 11-20-2012, 06:30 AM
franklekens franklekens is offline Macro to convert text to endnote? Windows XP Macro to convert text to endnote? Office 2003
Novice
 
Join Date: Jul 2010
Posts: 29
franklekens is on a distinguished road
Default

Thanks a lot. That was very sloppy of me.

In the meantime, I *have* got the original macro working, even with my EINDNOOT text in between the brackets. As far as I'm aware it worked fine in this form:


Code:
Sub MakeEndNotes()
Dim RngSel As Range, RngFnd As Range, StrNote As String
Application.ScreenUpdating = False
With Selection
  Set RngSel = .Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWildcards = True
    .Wrap = wdFindContinue
    .Forward = True
    .Text = "\[EINDNOOT ([0-9]{1;3})\]"
    Do While .Execute = True
      Set RngFnd = ActiveDocument.Range(Start:=Selection.Start, End:=Selection.End)
      StrNote = Mid(RngFnd.Text, 2, Len(RngFnd.Text) - 2)
      ActiveDocument.Endnotes.Add RngFnd, , StrNote
      RngFnd.Text = vbNullString
    Loop
  End With
End With
RngSel.Select
Set RngFnd = Nothing: Set RngSel = Nothing
Application.ScreenUpdating = True
End Sub
I'm still not sure what all of the items refer to, my knowledge of the macro language doesn't go that far. Which makes the macro you refer to even more daunting for me. :-)

And since that also stalls on my Word, for the moment I'll stick to this one. (And try to be a little cleverer in how I add endnote indications in my text, so they're easier to search & replace or convert into real endnotes and back.)
Thanks anyway. Great that this thread is here for reference' sake.
Reply With Quote
  #19  
Old 11-21-2021, 05:34 PM
vbafun vbafun is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Novice
 
Join Date: Nov 2021
Posts: 2
vbafun is on a distinguished road
Default 255 Character Limit

Hi Paul,

I used the endnote demo and it works perfectly to extract the endnotes from the inline texts. However if the characters in each inline citation greater than 255 Character the endnote is not working. is there a way to bypass the 255 character limitation?
Reply With Quote
  #20  
Old 11-21-2021, 07:00 PM
Guessed's Avatar
Guessed Guessed is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
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

It looks like the ActiveDocument.Endnotes.Add command can take a Variant instead of a string. Try passing in the RngFnd range instead of converting that to a string and then passing that to the Endnotes.Add command.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #21  
Old 11-21-2021, 07:16 PM
vbafun vbafun is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Novice
 
Join Date: Nov 2021
Posts: 2
vbafun is on a distinguished road
Default 255 Character Limit

Hi Andrew,
Is this the way to do it?
ActiveDocument.Endnotes.Add Range:=myRange,
Reply With Quote
  #22  
Old 03-26-2022, 03:47 AM
Bella Bella is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Novice
 
Join Date: Mar 2022
Posts: 4
Bella is on a distinguished road
Default

Hi macropod,
I have seen your code here and on stackoverflow, but I'm unable to apply it. I created a macro using Visual Basic in Word and copied/pasted the code there. When I hit run, nothing happened. Could you please show me how to use the code? Thanks in advance!
Reply With Quote
  #23  
Old 03-26-2022, 05:34 AM
macropod's Avatar
macropod macropod is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For PC macro installation & usage instructions, see: Installing Macros
For Mac macro installation & usage instructions, see: Word:mac - Install a Macro
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #24  
Old 03-26-2022, 07:12 PM
Bella Bella is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Novice
 
Join Date: Mar 2022
Posts: 4
Bella is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
For PC macro installation & usage instructions, see: Installing Macros
For Mac macro installation & usage instructions, see: Word:mac - Install a Macro
Hi Paul, Thanks so much for your prompt reply. I'm using EndNoteX9 to change in-text citations to unformatted citations in {}. I wrote the following code to cut and paste all the unformatted citations to endnotes, but it says "invalid or unqualified reference". Could you please help me understand why?
Sub Convert ()
Do While .Find
.Selection = "\{[!\{]@\}"
Selection.Cut
With Selection
With .EndnoteOptions
.Location = wdEndOfDocument
.NumberingRule = wdRestartContinuous
.StartingNumber = 1
.NumberStyle = wdNoteNumberStyleArabic
End With
.Endnotes.Add Range:=Selection.Range, Reference:=""
End With
Selection.Paste
Loop
End Sub
Reply With Quote
  #25  
Old 03-29-2022, 02:19 PM
macropod's Avatar
macropod macropod is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub MakeEndNotes()
Application.ScreenUpdating = False
Dim eNt As Endnote
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWildcards = True
    .Forward = True
    .Format = False
    .Wrap = wdFindStop
    .Text = "\{[!\{]@\}"
  End With
  Do While .Find.Execute = True
    .Characters.First.Text = vbNullString
    .Characters.Last.Text = vbNullString
    Set eNt = .Endnotes.Add(Range:=.Duplicate, Text:="")
    eNt.Range.FormattedText = .FormattedText
    .Text = vbNullString
  Loop
End With
Set eNt = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #26  
Old 03-29-2022, 02:28 PM
Bella Bella is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Novice
 
Join Date: Mar 2022
Posts: 4
Bella is on a distinguished road
Default

Thanks so much, Paul! It worked. I want to keep the same format and the {} so that I can use EndNote app to turn them into actual notes. What on the code need to be changed?
Reply With Quote
  #27  
Old 03-29-2022, 02:32 PM
macropod's Avatar
macropod macropod is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could delete:
Code:
    .Characters.First.Text = vbNullString
    .Characters.Last.Text = vbNullString
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #28  
Old 03-29-2022, 02:58 PM
Bella Bella is offline Macro to convert text to endnote? Windows 10 Macro to convert text to endnote? Office 2016
Novice
 
Join Date: Mar 2022
Posts: 4
Bella is on a distinguished road
Default

It's perfect. Thank you so much, Paul! I really appreciate it.
Reply With Quote
Reply

Tags
convert text to endnote, macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to convert text to endnote? Creating macro to convert/print to pdf shabbaranks Word 3 05-18-2011 08:59 AM
Macro to convert text to endnote? Cross-reference endnote text smed Word 3 01-14-2011 03:34 PM
convert html to text at opening etfjr Word 0 12-13-2010 11:14 AM
Convert Number to Text devcon Word 0 07-10-2010 01:16 AM
Convert Dollar amount to text GeorgeLawshe Word 0 03-07-2010 10:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:43 PM.


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