From: CJ on 26 Jan 2010 15:21 How can I change how the footnotes appear at the bottom of the page in a document that already exists with footnotes in it? Issues are: (1) Sometimes there is one space, (2) sometimes there is a tab before the footnote text -- both of which I think I've handled in the code below, and (3) in rare occassions, there is no space before the footnote text -- and I have no idea what to do in that case! I want to programatically edit all footnotes to appear with two spaces before the footnote text. Can someone please take a look and advise me (1) have I dealt with the first two issues properly? and (2) how to properly handle issue 3? I would be ever so grateful for help! Here is code: Sub FixFootnotes() Dim s As Integer For s = 1 To ActiveDocument.Footnotes.Count ActiveDocument.Footnotes(s).Range.Select With Selection .Collapse Direction:=wdCollapseStart .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend If Selection.Text = Chr(32) Then .TypeText Text:=" " If Selection.Text = vbTab Then .TypeText Text:=" " End With Next End Sub
From: DaveLett on 26 Jan 2010 16:13 Hi CJ, I think you're looking for something like the following: Dim lFoot As Long Dim sFoot As String Dim oRng As Range For lFoot = 1 To ActiveDocument.Footnotes.Count Set oRng = ActiveDocument.Footnotes(lFoot).Range.Paragraphs(1).Range oRng.MoveStart unit:=wdCharacter '''as long as the first character of the footnote is a space '''or tab, delete that first character Do While Left(oRng.Text, 1) = " " Or Left(oRng.Text, 1) = vbTab oRng.Characters(1).delete Loop '''insert two spaces before each footnote 'text' oRng.InsertBefore Text:=" " Next lFoot HTH, Dave
From: CJ on 27 Jan 2010 10:43 Dave, this is beautiful! Thank you so much! Do you have any idea whether there is a way to deal with the instance where there is no space before the footnote text? "DaveLett" wrote: > Hi CJ, > I think you're looking for something like the following: > > Dim lFoot As Long > Dim sFoot As String > Dim oRng As Range > > For lFoot = 1 To ActiveDocument.Footnotes.Count > Set oRng = ActiveDocument.Footnotes(lFoot).Range.Paragraphs(1).Range > oRng.MoveStart unit:=wdCharacter > '''as long as the first character of the footnote is a space > '''or tab, delete that first character > Do While Left(oRng.Text, 1) = " " Or Left(oRng.Text, 1) = vbTab > oRng.Characters(1).delete > Loop > '''insert two spaces before each footnote 'text' > oRng.InsertBefore Text:=" " > Next lFoot > > HTH, > Dave
From: DaveLett on 27 Jan 2010 12:59 Hi CJ, The provided routine accounts for that case with this line: '''insert two spaces before each footnote 'text' oRng.InsertBefore Text:=" " Notice that this line comes after the closing "Loop" for removing characters; therefore, the routine inserts two spaces before EVERY footnote. HTH, Dave "CJ" wrote: > Dave, this is beautiful! Thank you so much! Do you have any idea whether > there is a way to deal with the instance where there is no space before the > footnote text? > > "DaveLett" wrote: > > > Hi CJ, > > I think you're looking for something like the following: > > > > Dim lFoot As Long > > Dim sFoot As String > > Dim oRng As Range > > > > For lFoot = 1 To ActiveDocument.Footnotes.Count > > Set oRng = ActiveDocument.Footnotes(lFoot).Range.Paragraphs(1).Range > > oRng.MoveStart unit:=wdCharacter > > '''as long as the first character of the footnote is a space > > '''or tab, delete that first character > > Do While Left(oRng.Text, 1) = " " Or Left(oRng.Text, 1) = vbTab > > oRng.Characters(1).delete > > Loop > > '''insert two spaces before each footnote 'text' > > oRng.InsertBefore Text:=" " > > Next lFoot > > > > HTH, > > Dave
From: CJ on 3 Feb 2010 10:04 You know what? You are absolutely awesome! Thank you for such quick and expert help. It works exactly like I need it to. "DaveLett" wrote: > Hi CJ, > The provided routine accounts for that case with this line: > > '''insert two spaces before each footnote 'text' > oRng.InsertBefore Text:=" " > > Notice that this line comes after the closing "Loop" for removing > characters; therefore, the routine inserts two spaces before EVERY footnote. > > HTH, > Dave > > "CJ" wrote: > > > Dave, this is beautiful! Thank you so much! Do you have any idea whether > > there is a way to deal with the instance where there is no space before the > > footnote text? > > > > "DaveLett" wrote: > > > > > Hi CJ, > > > I think you're looking for something like the following: > > > > > > Dim lFoot As Long > > > Dim sFoot As String > > > Dim oRng As Range > > > > > > For lFoot = 1 To ActiveDocument.Footnotes.Count > > > Set oRng = ActiveDocument.Footnotes(lFoot).Range.Paragraphs(1).Range > > > oRng.MoveStart unit:=wdCharacter > > > '''as long as the first character of the footnote is a space > > > '''or tab, delete that first character > > > Do While Left(oRng.Text, 1) = " " Or Left(oRng.Text, 1) = vbTab > > > oRng.Characters(1).delete > > > Loop > > > '''insert two spaces before each footnote 'text' > > > oRng.InsertBefore Text:=" " > > > Next lFoot > > > > > > HTH, > > > Dave
|
Next
|
Last
Pages: 1 2 Prev: Macro use Next: Making a document open a userform in the originating template |