Results 1 to 9 of 9
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why I record macros (all)

    On-the-fly tables macro.
    ------------------------

    I have many macros that deal with tables, but from time to time I need a quickie. Here's how I do it.

    I have a word document with a slew of tables. Each table appears on its own page, separated by a WEIRD section break. Edit-replace won't cut it, but I discover that if I tap the delete key at the right point, the pseudo-break will be removed, and I can fit THREE tables per page instead of one.

    The document is 315 pages long. I don't have time to do it manually. A macro is called for.



    What action is required?
    ------------------------

    I switch to Normal View. I can see the section break just below the table.

    I essay with Alt-A, A (selects the entire table), and the right-arrow key (places the cursor on the section break). I tap Enter to provide a paragraph separator, then Delete to remove the break. Looks fine. Those are the four actions I want to apply to each of the 315 tables.

    Ctrl-Z twice to undo what I just did, then into macro recorder.



    Recording the macro
    -------------------

    Ctrl-Home takes me to the top of the document.

    Tools, Macro, Record.

    I choose Toolbars and drag the Normal.newmacros.Macro1 to my Standard toolbar. Yes, it looks ugly, but it'll work just fine.

    Close the customize box, and the familar "Stop recording" toolbar appears. here we go:-


    Alt-A, A, Enter, Delete. Remember that from above? WE have recorded the four small steps required to fix ONE of the 315 tables.

    Stop recording.


    Visual Basic Trick.
    -------------------

    Open up the Visual Basic Editor (Tools, Macro, Visual Basic Editor) and double-click like mad until you have opened up the module newMacros in Normal.

    You'll see something like this:

    <pre>Option Explicit

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 11/08/01 by Christopher Greaves
    '
    Selection.Tables(1).Select
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeParagraph
    Selection.Delete Unit:=wdCharacter, Count:=1
    End Sub
    </pre>



    See the four actions we took. Neat, eh?


    Now we make two small modifications to fix all 315 tables:

    We want this macro to run continuously until we have processed all the tables.

    Immediately before the first of our four actions start a new line and type:-
    <pre>while selection.information(wdwithintable)
    </pre>


    Immediately after the fourth action, start a new line and type:-
    <pre>wend
    </pre>


    That's it!

    Your VBE window now looks like this:

    <pre>Option Explicit

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 11/08/01 by Christopher Greaves
    '
    While Selection.Information(wdWithInTable)
    Selection.Tables(1).Select
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeParagraph
    Selection.Delete Unit:=wdCharacter, Count:=1
    Wend
    End Sub

    </pre>






    Alt-tab to Word and click on the Macro1 on the toolbar.


    Hey look! Only 105 pages now!!!!!

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

    Re: Why I record macros (all)

    It reads just like a novel

    ...with happy ending and all.
    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>

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

    Re: Why I record macros (all)

    > It reads just like a novel

    ... or perhaps a novella: a relatively long narrative with a more or less complex plot or pattern of events, often characterized by moral teaching or satire.
    It starts off in an equilibrium, then the protagonist goes through a series of mishaps, makes some decisions, and finally a new equilibrium is reached (with the open possibility of a similar story starting there).

    (At least that's what I remember from my long-ago German classes, about that literary genre which was quite popular with 19th century German authors)

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

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why I record macros (all)

    > German classes

    Aren't you confusing german with germane?


    BTW, where is germane? haven't seen her lately.


    I wrote this more in reponse to another recent thread in Access, about Macros.

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

    Re: Why I record macros (all)

    OK, something more germane:
    If you had "NewPage" section breaks between the tables, and want "Continuous" section breaks, another possibility would have been
    <pre>Dim mySection As Section

    For Each mySection In ActiveDocument.Sections
    mySection.PageSetup.SectionStart = wdSectionContinuous
    Next mySection</pre>


    But I'd probably have recorded the macro, too <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

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

  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: Why I record macros (all)

    Shot from the waist, and hit my foot:

    <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>You wouldn't need a macro for what my macro does: Just select the document, and change all section breaks to "Continuous" in "File > Page Setup > Page Layout".

    <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>It doesn't do what you want: remove the section breaks, and insert Paragraph Marks to keep the tables apart.

    Section breaks are easily added, but hard to get rid of. I guess your macro is the best that can be done in the circumstances -- if you are very sure there really is a section break after each of the 350 tables; else I'd search for section breaks in a loop, then insert a paragraph mark and delete the section break:
    <pre> Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "^b"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    While Selection.Find.Execute
    Selection.Collapse Direction:=wdCollapseStart
    Selection.TypeParagraph
    Selection.Delete Unit:=wdCharacter, Count:=1
    Wend</pre>


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

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why I record macros (all)

    >OK, something more germane

    I agree with you. Two factors prompted my posting:

    1) The section breaks introduced by mail-merge seem to be different from section breaks that cane be replaced via the Edit-Find box. I'll look into them one day, when I have a break (grin!)

    2) I was waiting for a task that lent itself to on-the-fly macros with a simple (to me at any rate) means of terminating a repetitive process. Partly in response to a comment in the Access forum.


    Of course, my fervent hope is that 232 loungers who have never recorded a macro will sieze the chance to see what it's all about. Once everyone in the world is writing macros in everything, there'll be enough spare computing power lying around that all those extra machine cycles can be used by SETI, and I won't have to keep coming back to the lounge in the vain hopes that (very big grin). There's a monty pythonesque song that ends "And pray that there's intelligent life someowhere up in space, because there's none at all down here on earth".

  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: Why I record macros (all)

    <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>I'm all with you in your worthy quest to make macros more popular.

    To your point 1):
    The section breaks are probably very ordinary section breaks.
    Word will find section breaks and paragraph marks that are right before a table easily enough.
    But when it comes to replacing them with something else, Word balks and refuses at the jump.
    Don't know what the hurdle is; since these characters contain the formatting of preceeding sections/paragraphs, perhaps Word cannot make the replacement without risking to loose that information.

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

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why I record macros (all)

    > The section breaks are probably very ordinary section breaks.

    Thanks. I'll bear this in mind next time I do a mail-merge.

    Of course, *my* definition of "ordinary" is that they behave as they should. It's a tradgedy that they don't appear to behave in this case. At any one time there are probably ten people struggling to replace the darn things, as the morning sun ascends on yet another continent.

Posting Permissions

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