This should be the simplest thing, but it is not working (perhaps because I’m using a Mac?)
I am trying to make a Macro in MS Word that creates a button that when I press it, does the Tools: Word Count function. I have done this in the past on a PC with no problem. However, despite trying to record the action, the resulting macro is blank:
If I just knew what the syntax/command is for Word Count I could edit it in manually, only I don’t. The Visual Basic help doesn’t seem to be installed, and nowhere on the internet can I find a list of simple commands. Googling “Word count macro” and similar keeps throwing up results for some downloadable program, which isn’t what I want (nor will it work on my Mac).
Oh that is kewl - thanks! I substituted ActiveDocument for Selection and it does exactly what I want!
How do you find out the syntax/commands in the first place? If I could find a simple list, with some examples of very basic macros, I could do so much more. (As the Record function isn’t working I sadly can’t create any basic ones myself to pick apart and fiddle with).
I’m very rusty on VB. for instance I would put some words like “there are " before and " words in the selection” after, but I don’t know how to join strings in vb (I know quite well in C++)
I found the answer just by messing about with word. I did a search for ‘count’ and eventually found that. I have a feeling it might not be possible to run word’s own word count dialog but I could easily be wrong.
Not to nitpick Lobsang’s method too much (it was my first attempt as well) but it counts punctuation and spaces as words too, which may throw off your stats.
I suggest something along the lines of:
Public Sub view_WC()
MsgBox “There are " & ActiveDocument.ComputeStatistics(wdStatisticWords) & " words.”
End Sub
which I found by looking in Tools->macros->macros in (word commands) noting that ToolsWordCount did what I wanted and typing that into the VB help, which gave me the code above. A mine of useful info that particular method.
The example above works under Word 2003, I don’t have another machine about with an older version to test on, sorry.