Results 1 to 13 of 13
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Store Paragraph Formatting (Word 97SR2)

    I need to store paragraph formatting settings for use later in document. What's the best way to do this?

    The situation is this: user creates a double-indented paragraph by clicking my double-indent button. The sub to create the double-indent needs to record the current paragraph settings (line spacing, first line indent, margins, etc.) then change the margins to create the double indenting (this part works fine). After the user finishes the "block quote" they'll press another button the code for which needs to apply the stored paragraph setting to the paragraph following the double-indented paragraph(s). Make sense?

    I was thinking I could hijack the format painter, but what if the user uses it during the block quote? Another idea is to hijack the clipboard to store a paragraph mark, but this is Office 97 -- only one clipboard item. Same problem as using the format painter. Where could I store the desired paragrah settings? In autotext?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    Hi Kevin,

    At the risk of being a bore: Use a ParagraphFormat object? (Dim myParagraphFormat as Paragraph Format : Set myParagraphFormat = Selection.ParagraphFormat.Duplicate ...)

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    This is nice, Klaus, but I need to *store* the paragraph format for later use -- later means someplace else in the document session. The code that creates the myParagraphFormat object has long since ended and the object deleted. The catch here is how to store the settings.

    Keep thinking. Thanks.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    Then how 'bout using Static or Public instead of Dim?

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    From Help: Static statement retain their values as long as the code is running.

    The code is no longer running; therefore Static will not work. I think I'm going to create a temporary style then reapply the style when the user clicks the un-double indent.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    Do you want to close down Word in-between? I didn't think so from your original question.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  7. #7
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    Just try it:
    <pre>Public myPF As ParagraphFormat
    Sub SetmyPF()
    Set myPF = Selection.ParagraphFormat.Duplicate
    End Sub
    Sub GetmyPF()
    Selection.ParagraphFormat = myPF
    End Sub</pre>

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  8. #8
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    ... or using Static:
    <pre>Sub GetSetmyPF()
    Static myPF As ParagraphFormat
    If myPF Is Nothing Then
    Set myPF = Selection.ParagraphFormat.Duplicate
    MsgBox "Remembered Paragraph Format"
    Else
    Selection.ParagraphFormat = myPF
    Set myPF = Nothing
    MsgBox "Applied Paragraph Format"
    End If
    End Sub</pre>


    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    No. The Word session does not end. I tried Static and it didn't work. If it's supposed to, tell me what I'm doing wrong. I have never been able to get Static to work across mods.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    As KLaus indicated, use a Public variable in a regular code module.

    As long as that project is open, the variable is available.

  11. #11
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    You'd use "Static" to keep the variable value in the Sub between calls.
    The last macro I posted should alternatingly remember and apply the paragraph format.
    Run GetSetmyPF on a right-adjusted paragraph, and it will remember that ParagraphFormat. The next time you call the macro (for example with the cursor in a left-adjusted paragraph) it will apply the format.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  12. #12
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    This is why the documentation cannot be trusted. Lomax says that "although [a static variable] has procedure-level scope, it has module-level lifetime." The lifetime of a module-level variable is "as long as the module remains in memory." In a global template this could be a good long time!

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Store Paragraph Formatting (Word 97SR2)

    Klause,

    Your help is much appreciated. Both examples work fine. My problem was trying to access one sub's Static var from another sub. I'll implement my solution using your Public example then. Thanks much.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •