It must be one of the most asked questions about macros - why has it not been addressed in the macro language after all these years?

Anonymous
2013-02-19T05:49:37+00:00

To those of us who are just users and not programmers, it seems like MS Word "macros" -- particularly recorded macros -- ought to include the capability to be easily constructed to (1) go to some identifiable place in a document and "do" some things starting from that point (such as "find" a new paragraph immediately followed by the word "publish", then go to the end of that line of text and insert "**") and then (here comes the sticking point) (2) repeat that series of activities over and over UNTIL some identifiable point is reached in the document [e.g., the end of the page; the end of the document; the end of the paragraph]. 

But for some reason, Word macros cannot be made to do that in an "easy for non-programmers to understand" sort of way.  I've had it explained to me several times that I must use references to "ranges" and/or "counts" and all sorts of other commands that seem overly complicated to just "go to a place and do this", then go to the next such place, and do the same thing", and keep doing that UNTIL . . .  It's certainly nothing that can be accomplished by recording a macro (as it logically should be.)   With help, I'll finally get a macro cobbled together to do what I need done.  But when the next occasion to do something like that comes along -- maybe a year later -- I've forgotten all those inscrutable concepts and I once again find myself just needing to record a macro doing some set of activities and then have it repeat itself through the document.

I know it's easy for programmers to understand all these arcane requirements to be able to get a macro to work through a document that way, but a lot of us "out here" are just regular users who occasionally need to be able to do repetitive tasks within a particular document and believe it should be easier to accomplish this sort of thing than it appears the macro language permits. 

Can someone explain why the macro language cannot be made to easily allow a macro to just do something like: 

   DO         [find <text>, then move from there to another point 8 characters away and then make some change to the text at that point], then     LOOP (DOing that same series of things again} UNTIL [the End of the Page or the End of the Document is reached], then just Stop the macro from further executing.

I'm sure I haven't used the right syntax above, but I hope you get the point - it ought to be just that simple to accomplish that sort of chore, but it isn't. 

Can anyone explain WHY the macro language CAN'T work this way or, if it could be made to do so, why Microsoft has not done it in all these many years while countless ordinary users have struggled with (and posted questions all over the Internet about) this specific concept?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2013-02-24T17:37:41+00:00

D PaulDalton,

Glad I could help and I understand your comments and concerns. 

Unfortunately, I don't know if your suggestions will ever get any traction even if they made it to the "right person.  In line with what Jay and Peter have said, my experience is that VBA becomes less and less complete as Word progresses rather than more and more complete.  For example, everything that you could do as a user with a drawing or shape object in Word 2003, you could do with VBA.  With the new graphics engine introduced with Word 2010, there are many things that a user can do that now cannot be done with VBA.  Most of the things that you can do with those graphics are not even recorded.  I suspect that the recorder will go away before it becomes anything like you envision.  Still, it is a good and valid vision.

Good luck.

Was this answer helpful?

0 comments No comments
Answer accepted by question author
Anonymous
2013-02-22T17:33:28+00:00

I have a few observations, and that's probably about all I'll be able to contribute here.

In order to get much further with getting Microsoft to do this, you'll need to get your idea onto their agenda. While it's possible that ideas posted here sometimes get some attention from them, you can't guarantee it: you aren't really dealing with Microsoft people (it's mostly volunteers), and certainly not the Microsoft product group people, in here. So you either need to know someone, or find a proxy (either someone close or perhaps an influential corporate that can see the value of the idea). As for timing, I don't know what their product cycle looks like now, either - it could well be changing rapidly as their Office 365 subscription service develops. But if it's the old cycle, I would guess they already have the outline if not most of the details for the version after 2013 and may be thinking about ideas after that. Also, I would be very surprised if they did not want to be absolutely sure of their ground as far as Intellectual Property is concerned.

On the technical front, the biggest technical questions for me are "what can be done in the 'DO' part of the feature?" (i.e. the one you described a few messages back)

If it's "execution of an arbitrary macro", then it can do anything VBA can do, form "something sensible" to "accidentally trash every file on the system." It can also contain infinite loops, code that results in untrappable errors - at least not trappable by VBA - and doubtless other things I haven't even thought about that may result in dismay for the user.

As long as the user is willing to take responsibility for their part of the code, I don't see any technical showstoppers*.* But that doesn't mean that such problems won't turn up.

From a support perspective though, having a half-and-half feature like that is a bit of a liability, to say the least.

Going to a slightly more detailed level, when I read your earlier messages, I got the impression that you were keen to avoid the more techie stuff involving selections, ranges etc. The trouble is that if the user still has to write VBA, e.g. to find something then move a few words to the right or whatever, they still have to understand that stuff. What's more, in the general case some code will function in (say) a paragraph in the main body of the document, but fail in a footer (say). In other words, in many cases the user would need to understand even more about their code.

When I first read your question, I had a slightly different idea as to what you were driving at. To me, how you avoid dealing with "allowing any piece of VBA" is to try to identify a small but potent set of things the user might want to do (obviously reducing the generality obtainable in VBA) and allow them to do those things and nothing else. That's one of the reasons I suggested that a change to the recorder might be needed - you'd only be able to record the things that the feature is designed to allow. Then the feature takes responsibility for making all that stuff happen. How to do that technically is a detail, but perhaps specify that the DO macro only contains calls to a number of predefined subs/functions that have been designed to behave well within the overall structure of the feature. Or define a completely new, small, non-VBA language and some VBA to interpret it.

Finally, I know we have been taking about Word and VBA. But really, we're talking about providing a set of features for repetitive processing. The Web App version of Word doesn't have any of that stuff, and perhaps it is intended that it never will. But because it doesn't have VBA, it would I think benefit far more from a feature to let its users do something like "do this in every paragraph that begins with 'Jack Robinson'"

Was this answer helpful?

0 comments No comments

39 additional answers

Sort by: Newest
  1. Anonymous
    2013-02-21T14:17:54+00:00

    FWIW, I get the impression that your question is already beginning to morph from a "is it possible, and if so, why hasn't it been done, by Microsoft" question into a "how would I (or someone) go about it" question. If you want to pursue the latter you'll probably be better off asking a new, separate question, pinning down the specification as best you can. You never know what someone might be able to come up with. However, if a part of the problem is that the existing recorder does not record the action that you want to repeat, implementing a "recorder alternative" could be a large task. 

    As far as the "why" question is concerned, I started with a simple example because I think it illustrates that it's hard even to get what appear to be very simple things right, even when you're in a "green field" situation where you have some chance of making the product as capable and extensible as you want. And Microsoft hasn't been in that situation with Word for a very long time now.

    To get lots of things right, you're going to have to make a large number of conceptual and design choices. Once you're done, it will be hard to modify those choices. Once you have millions of copies out there, with people relying on feature A or format B, even what appears to be a minor fix may involve cost and risk, as Jay mentions. Doing anything major is probably only going to happen if it's considered essential for commercial survival. If it cannot be accommodated by any existing extensibility mechanism and requires significant changes to the existing object model, it's even less likely to happen. And I suspect that that is what would be necessary to make changes to, say,

    a. the macro recording process

    b. the find/replace process

    which I think might be needed for a good implementation of what you describe. But by way of example, although find/replace has had some tweaks over the years, I'd suggest that a lot of people would probably be rather pleased if the "regular expressions" it can use were a bit richer, and in some cases, more reliable. But even that apparently simple thing hasn't changed. And that's probably either because it's actually hard or risky to do, or because it has simply never reached the top of the to-do list.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-02-20T23:51:19+00:00

    Thank you Peter.  I sincerely appreciate the well thought-out response. 

    I think your example actually provides a discussion opportunity, because -- while there may be circumstances where someone needs unusual considerations taken into account to come up with the total number of words in a document, it appears to me that Microsoft already has settled on a particular combination of those considerations as a "standard" for doing that and, using that standard, has included in Word a tool that provides an answer to that question (as as well as how many characters & spaces are in the document).  So -- to me -- counting the words in a document provides an example of something that could be done by a macro, but where MS has decided to make it easier for the user to get the basic information by "hard-coding" some standard assumptions about what is and is not a "word" and then providing the number.  If MS also happened to mention that its assumptions did not count any "Non-joining-oojamaflip" and the IT Journalist knew he really needed those counted, then that would be a good reason why he would need to come up with a macro that included all of the complexities you reference. 

    So let's say Microsoft had not already happened to have thought to include "word count" within Word and the only way users could get any count of the total number of words in their document was to write their own macro that would have to take into account ALL of the unusual ""Non-joining-oojamaflip"-type considerations.  In the first place, there would be an awful lot of users who would give up and use the old "print it out and manually count" method.  Then there would be others who would try to use the macro language to do it, with varying degrees of success.  At some point, I've got to believe enough people would say to Microsoft "I don't care about the "Non-joining-oojamaflip" -- count it or not and make whatever standard assumptions you deem appropriate, but please just find a way to give me a standardized (you pick the standard) count without my having to program a complicated macro." 

    That's the way I feel about providing a tool that will make a macro do whatever it does over and over within a document UNTIL it has reached the end of the [paragraph; section; page; or document].  And then, MS should identify the limitations of the tool (e.g., "This option [will or will not (frankly, I don't care, just tell me)] affect headers, footers, footnotes, endnotes, comments [or whatever] that may be encountered in the document.). 

     You asked a couple of questions that I don't know that I understand well enough to try to answer: 

            a. how do we define what exactly a Word macro language should be able to do? Even at

                 its simplest, "What questions should the macro language enable you to answer?"

    To me, it's not what the macro language itself should be able to do, but whether and what additional tools can be provided that could automate and maximize the accessibility of the macro capability for the benefit of more users. 

    b. if the macro language just had to be able to deal with the example you give, what would

               it really have to do (in the general case, bearing in mind that a document isn't just a single

               stream of text, ya da da...)

    Well, as I said before, I would propose that a button or checkbox Option be added to "Repeat application of this macro to all text in", next to which would be radio buttons for choosing between:

    1. this entire paragraph
    2. this entire page
    3. this entire section
    4. this entire document
    • Selection of any of which would activate checkboxes to have it also apply within any encountered:
    • header
    • footer
    • footnote
    • endnote, or
    • comment

    Not being a programmer, (and like Donald Rumsfeld) there probably are considerations that are "known unknowns" to me, but which a programmer addressing this would "know" to take into account.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-02-20T22:03:20+00:00

    Please pay attention to what the OP is saying. Nothing you have said so far suggests that you have even taken the trouble to understand what the OP is saying.

    Was this answer helpful?

    0 comments No comments