Poker Forums : 500,000+ Poker Forum Posts
Texas Holdem Odds Calculator
Odds Chart & Calculators
Poker Rakeback
Rakeback Comparison
Party Poker Bonus
AND YOU'LL GET FREE POKER GIFTS WITH SIGNUPS!
FAQ  |   Search Forum  |  Watched Topics Memberlist  |  Usergroups  |  Register  |  Profile  |  Log in   |  Log in to check your private messages
----> Dogs: VBA stuff

 
Post new topic   Reply to topic   printer-friendly view    Internet Texas Hold'em Forum Index  -> Off-Topic / Non-Poker Related  | Search
Author Message
Misunderstud
1K Club


Joined: 10 Jan 2006
Posts: 1656
Location: Here, stupid

PostPosted: Fri Sep 05, 2008 3:53 am    Post subject: ----> Dogs: VBA stuff Reply with quote

Remember those macros you wrote for me? (Link)

Well, they do what it says on the tin, but I've also noticed that they remove formatting such as bold and italic from the notes. I wondered if you could spot any obvious reason why this should be so, and any easy way of preventing it? Don't worry if not, though.

Cheers.
Back to top
Dogs
1K Club


Joined: 17 May 2006
Posts: 1171

PostPosted: Sat Sep 13, 2008 6:20 pm    Post subject: Reply with quote

How do these shape up?

Code:
Sub FootnoteAfterParagraphFormatted()
'
' FootnoteAfterParagraphFormatted Macro
'
'
    Dim afootnote As Footnote
    Dim refrange As Range
    Dim sectionno As Integer
    Dim lastsectionno As Integer
    Dim footnotecount As Integer
    Dim paragraphno As Integer
    Dim lastparagraphno As Integer
    Dim paragraphcount As Integer
    Dim footnoterange As Range

    lastsectionno = 0
    footnotecount = 0
    lastparagraphno = 0
    paragraphcount = 0

    For Each afootnote In ActiveDocument.Footnotes

        Set refrange = afootnote.Reference
        refrange.Start = ActiveDocument.Range.Start
        sectionno = refrange.Sections.Count
        paragraphno = refrange.Paragraphs.Count

        If sectionno > lastsectionno Then
            lastsectionno = sectionno
            footnotecount = 1
        Else
            footnotecount = footnotecount + 1
        End If

        If paragraphno = lastparagraphno Then
            paragraphcount = paragraphcount + 1
        Else
            paragraphcount = 1
            lastparagraphno = paragraphno
        End If

        For i = 1 To paragraphcount

            refrange.End = refrange.End + 1
            refrange.EndOf Unit:=wdParagraph, Extend:=wdExtend

        Next i
       
        Set footnoterange = afootnote.Range.FormattedText
        footnoterange.Copy

        refrange.InsertAfter "a" & footnotecount & "a "
        refrange.Start = refrange.End
        refrange.Paste
        refrange.InsertAfter vbCr
               
       
        afootnote.Reference.InsertBefore "a" & footnotecount & "a"

    Next afootnote
   

    For Each afootnote In ActiveDocument.Footnotes

        afootnote.Reference.Delete

    Next afootnote

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False
       
    End With

    With Selection.Find

        .Text = "(a)([0-9]{1,})(a)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll


End Sub


Code:
Sub FootnoteAfterSectionFormatted()
'
' FootnoteAfterSectionFormatted Macro
'
'
    Dim afootnote As Footnote
    Dim refrange As Range
    Dim sectionno As Integer
    Dim lastsectionno As Integer
    Dim footnotecount As Integer
    Dim secrange As Range
    Dim footnoterange As Range
           
    lastsectionno = 0
    footnotecount = 0

    For Each afootnote In ActiveDocument.Footnotes

        Set refrange = afootnote.Reference
        refrange.Start = ActiveDocument.Range.Start
        sectionno = refrange.Sections.Count
       
        Set secrange = ActiveDocument.Sections(sectionno).Range
               
        If sectionno > lastsectionno Then
            lastsectionno = sectionno
            footnotecount = 1
        Else
            footnotecount = footnotecount + 1
        End If

        For i = 1 To footnotecount

            secrange.End = secrange.End - 1
           
        Next i
       
        Set footnoterange = afootnote.Range.FormattedText
        footnoterange.Copy
               
        secrange.InsertAfter vbCr & "a" & footnotecount & "a "
               
        secrange.Start = secrange.End
        secrange.Paste
        secrange.InsertAfter vbCr
                               
        afootnote.Reference.InsertBefore "a" & footnotecount & "a"

    Next afootnote

    For Each afootnote In ActiveDocument.Footnotes

        afootnote.Reference.Delete

    Next afootnote

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False
       
    End With

    With Selection.Find

        .Text = "(a)([0-9]{1,})(a)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll
   
End Sub



Code:
Sub FootnoteAfterEndFormatted()
'
' FootnoteAfterEndFormatted Macro
'
'
    Dim afootnote As Footnote
    Dim refrange As Range
    Dim sectionno As Integer
    Dim lastsectionno As Integer
    Dim footnotecount As Integer
    Dim footnoterange As Range
    Dim docrange As Range
           
    lastsectionno = 0
    footnotecount = 0

    For Each afootnote In ActiveDocument.Footnotes

        Set refrange = afootnote.Reference
        refrange.Start = ActiveDocument.Range.Start
        sectionno = refrange.Sections.Count
                       
        If sectionno > lastsectionno Then
            lastsectionno = sectionno
            footnotecount = 1
        Else
            footnotecount = footnotecount + 1
        End If
       
        Set footnoterange = afootnote.Range
        footnoterange.Copy
               
        ActiveDocument.Range.InsertAfter vbCr & "a" & footnotecount & "a "
        Set docrange = ActiveDocument.Range
        docrange.Start = docrange.End
        docrange.Paste
       
        afootnote.Reference.InsertBefore "a" & footnotecount & "a"

    Next afootnote
   
   
    For Each afootnote In ActiveDocument.Footnotes

        afootnote.Reference.Delete

    Next afootnote

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False
       
    End With

    With Selection.Find

        .Text = "(a)([0-9]{1,})(a)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

End Sub


One question - are there any types of formatting other than bold and italic?
Back to top
Misunderstud
1K Club


Joined: 10 Jan 2006
Posts: 1656
Location: Here, stupid

PostPosted: Sun Sep 14, 2008 12:12 pm    Post subject: Reply with quote

They seem to work fine. Thanks.

There are other formattings, yes: bold, underlined, italic-underlined, bold-underlined, bold-italic and bold-italic-underlined would cover most of the bases. But the doc I tested had all those and all were preserved, so that doesn't appear to be a concern.

The other situation I need to address is that of simply unlinking existing endnotes from the text without losing formatting. You'll recall there was code for that in the original post, so maybe that could be similarly modified?

Finally, also as previously, a second set that do the same thing but replace the superscript numbers preceding each note with a normal-sized number followed by a full stop and a space would complete the picture . . .

. . . if you don't have anything more pressing to do Smile
Back to top
Dogs
1K Club


Joined: 17 May 2006
Posts: 1171

PostPosted: Sun Sep 14, 2008 1:23 pm    Post subject: Reply with quote

I asked about the formatting as I found a funny where it is preserved in the original text, but if that ended with a formatted word, then the next number took on that same format. So if the first one read:

1. test ending in bold

then the next one looked like this:

2. another test.
(that number 2 is in bold)

To iron it out, I needed to include something to not format the numbers. It's currently the bit that reads:

Code:
    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False

    End With


You should add in Underline:

Code:
    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False
        .Underline = False
       
    End With
Back to top
Dogs
1K Club


Joined: 17 May 2006
Posts: 1171

PostPosted: Sun Sep 14, 2008 1:31 pm    Post subject: Reply with quote

Modified without superscript:

Code:
Sub FootnoteAfterEndFormattedReg()
'
' FootnoteAfterEndFormattedReg Macro
'
'
    Dim afootnote As Footnote
    Dim refrange As Range
    Dim sectionno As Integer
    Dim lastsectionno As Integer
    Dim footnotecount As Integer
    Dim footnoterange As Range
    Dim docrange As Range
           
    lastsectionno = 0
    footnotecount = 0

    For Each afootnote In ActiveDocument.Footnotes

        Set refrange = afootnote.Reference
        refrange.Start = ActiveDocument.Range.Start
        sectionno = refrange.Sections.Count
                       
        If sectionno > lastsectionno Then
            lastsectionno = sectionno
            footnotecount = 1
        Else
            footnotecount = footnotecount + 1
        End If
       
        Set footnoterange = afootnote.Range
        footnoterange.Copy
               
        ActiveDocument.Range.InsertAfter vbCr & "b" & footnotecount & "b. "
        Set docrange = ActiveDocument.Range
        docrange.Start = docrange.End
        docrange.Paste
       
        afootnote.Reference.InsertBefore "a" & footnotecount & "a"

    Next afootnote
   
   
    For Each afootnote In ActiveDocument.Footnotes

        afootnote.Reference.Delete

    Next afootnote

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False
        .Underline = False
       
    End With

    With Selection.Find

        .Text = "(a)([0-9]{1,})(a)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll
   
    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = False
        .bold = False
        .Italic = False
        .Underline = False
       
    End With

    With Selection.Find

        .Text = "(b)([0-9]{1,})(b)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

End Sub


Code:
Sub FootnoteAfterSectionFormattedReg()
'
' FootnoteAfterSectionFormattedReg Macro
'
'
    Dim afootnote As Footnote
    Dim refrange As Range
    Dim sectionno As Integer
    Dim lastsectionno As Integer
    Dim footnotecount As Integer
    Dim secrange As Range
    Dim footnoterange As Range
           
    lastsectionno = 0
    footnotecount = 0

    For Each afootnote In ActiveDocument.Footnotes

        Set refrange = afootnote.Reference
        refrange.Start = ActiveDocument.Range.Start
        sectionno = refrange.Sections.Count
       
        Set secrange = ActiveDocument.Sections(sectionno).Range
               
        If sectionno > lastsectionno Then
            lastsectionno = sectionno
            footnotecount = 1
        Else
            footnotecount = footnotecount + 1
        End If

        For i = 1 To footnotecount

            secrange.End = secrange.End - 1
           
        Next i
       
        Set footnoterange = afootnote.Range.FormattedText
        footnoterange.Copy
               
        secrange.InsertAfter vbCr & "b" & footnotecount & "b. "
               
        secrange.Start = secrange.End
        secrange.Paste
        secrange.InsertAfter vbCr
                               
        afootnote.Reference.InsertBefore "a" & footnotecount & "a"

    Next afootnote

    For Each afootnote In ActiveDocument.Footnotes

        afootnote.Reference.Delete

    Next afootnote

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False
        .Underline = False
       
    End With

    With Selection.Find

        .Text = "(a)([0-9]{1,})(a)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll
   
    Selection.Find.Execute Replace:=wdReplaceAll
   
    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = False
        .bold = False
        .Italic = False
        .Underline = False
       
    End With

    With Selection.Find

        .Text = "(b)([0-9]{1,})(b)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll
   

End Sub


Code:
Sub FootnoteAfterParagraphFormattedReg()
'
' FootnoteAfterParagraphFormattedReg Macro
'
'
    Dim afootnote As Footnote
    Dim refrange As Range
    Dim sectionno As Integer
    Dim lastsectionno As Integer
    Dim footnotecount As Integer
    Dim paragraphno As Integer
    Dim lastparagraphno As Integer
    Dim paragraphcount As Integer
    Dim footnoterange As Range

    lastsectionno = 0
    footnotecount = 0
    lastparagraphno = 0
    paragraphcount = 0

    For Each afootnote In ActiveDocument.Footnotes

        Set refrange = afootnote.Reference
        refrange.Start = ActiveDocument.Range.Start
        sectionno = refrange.Sections.Count
        paragraphno = refrange.Paragraphs.Count

        If sectionno > lastsectionno Then
            lastsectionno = sectionno
            footnotecount = 1
        Else
            footnotecount = footnotecount + 1
        End If

        If paragraphno = lastparagraphno Then
            paragraphcount = paragraphcount + 1
        Else
            paragraphcount = 1
            lastparagraphno = paragraphno
        End If

        For i = 1 To paragraphcount

            refrange.End = refrange.End + 1
            refrange.EndOf Unit:=wdParagraph, Extend:=wdExtend

        Next i
       
        Set footnoterange = afootnote.Range.FormattedText
        footnoterange.Copy

        refrange.InsertAfter "b" & footnotecount & "b. "
        refrange.Start = refrange.End
        refrange.Paste
        refrange.InsertAfter vbCr
               
       
        afootnote.Reference.InsertBefore "a" & footnotecount & "a"

    Next afootnote
   

    For Each afootnote In ActiveDocument.Footnotes

        afootnote.Reference.Delete

    Next afootnote

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False
        .Underline = False
       
    End With

    With Selection.Find

        .Text = "(a)([0-9]{1,})(a)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = False
        .bold = False
        .Italic = False
        .Underline = False
       
    End With

    With Selection.Find

        .Text = "(b)([0-9]{1,})(b)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll


End Sub
Back to top
Dogs
1K Club


Joined: 17 May 2006
Posts: 1171

PostPosted: Sun Sep 14, 2008 1:35 pm    Post subject: Reply with quote

Endnote (did I modify the right script?)

Code:
Sub EndnoteFormatted()
'
' EndnoteFormatted Macro
'
'

    Dim aendnote As Endnote
    Dim refrange As Range
    Dim sectionno As Integer
    Dim lastsectionno As Integer
    Dim endnotecount As Integer
    Dim endnoterange As Range
    Dim docrange As Range
   
       
    lastsectionno = 0
    endnotecount = 0
   
   
    For Each aendnote In ActiveDocument.Endnotes
   
        Set refrange = aendnote.Reference
        refrange.Start = ActiveDocument.Range.Start
        sectionno = refrange.Sections.Count
       
        Set endnoterange = aendnote.Range.FormattedText
        endnoterange.Copy
                                         
        If sectionno > lastsectionno Then
            lastsectionno = sectionno
            endnotecount = 1
        Else
            endnotecount = endnotecount + 1
        End If
       
        ActiveDocument.Range.InsertAfter vbCr & "b" & endnotecount & "b. "
        Set docrange = ActiveDocument.Range
        docrange.Start = docrange.End
        docrange.Paste
                       
        aendnote.Reference.InsertBefore "a" & endnotecount & "a"
       

    Next aendnote
   

    For Each aendnote In ActiveDocument.Endnotes

        aendnote.Reference.Delete

    Next aendnote

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = True
        .bold = False
        .Italic = False
        .Underline = False
       
    End With

    With Selection.Find

        .Text = "(a)([0-9]{1,})(a)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll
   
    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find.Replacement.Font

        .Superscript = False
        .bold = False
        .Italic = False
        .Underline = False
       
    End With

    With Selection.Find

        .Text = "(b)([0-9]{1,})(b)"

        .Replacement.Text = "\2"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = True

        .MatchWildcards = True

    End With

    Selection.Find.Execute Replace:=wdReplaceAll
   
End Sub
Back to top
Misunderstud
1K Club


Joined: 10 Jan 2006
Posts: 1656
Location: Here, stupid

PostPosted: Mon Sep 15, 2008 3:58 am    Post subject: Reply with quote

Yep, all good. The only glitch I found (in all of them) was that if a note contains one or more hard returns then everything before the final hard return is formatted as footnote text rather than body text. (It still gets moved to the right place and the other formatting is preserved - it just comes up small.)

Not a major concern, though, since I run the macro before editing the text.
Back to top
Dogs
1K Club


Joined: 17 May 2006
Posts: 1171

PostPosted: Mon Sep 15, 2008 9:49 am    Post subject: Reply with quote

Are you able to format footnote text as body text across the document before you start? I assume the only real difference is font size.

The only way I could find to retain the formatting was to copy and paste the original text, so it's not too surprising if it retains qualities such as size. I'm not sure how I'd get around that.
Back to top
Misunderstud
1K Club


Joined: 10 Jan 2006
Posts: 1656
Location: Here, stupid

PostPosted: Mon Sep 15, 2008 10:31 am    Post subject: Reply with quote

Dogs wrote:
Are you able to format footnote text as body text across the document before you start? I assume the only real difference is font size.


Yes, that would be simple enough to do. The way round it would be to send the cursor to the first footnote (or endnote), select all the text from there to the end and apply a style. I was trying to do something similar in the workarounds I PM'd you about but, although I could do it with the document open, I couldn't make the macro I recorded while doing it work.

Not to worry, though; these will do just fine. Thanks again.
Back to top
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    Internet Texas Hold'em Forum Index -> Off-Topic / Non-Poker Related All times are GMT - 5 Hours
Page 1 of 1

 

Find More Poker Bonuses:


Powered by php.B.B 2.0.11 © 2001, 2002 php.B.B Group

Forum Archive

Texas Holdem Strategy

|

Internet Poker Bonus & Review

|

Texas Holdem Odds Calculator

|

PokerStars Bonus

|

Party Poker Bonus Code

|

Internet Texas Hold'em offers the Best Poker Bonus Codes & most in-depth Poker Rooms Reviews. Click on the Internet Poker Room of your choice for a full review.

"The information and opinions in this site are for informational and entertainment purposes only and are provided solely as the author's opinion. The site is not intended for use in areas where this information and/or advertisements may be considered illegal. Check your federal, state, and local laws concerning the legality of gambling and online gambling in your area."

Visit Pokerwonks, our Poker Blog Community and Internet Poker Rankings, providing poker tournament player rankings

Copyright 2008 © Dimat Online :: Internet Texas Holdem