Link to home
Create AccountLog in
Avatar of hindersaliva
hindersalivaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Word 2013 - Count the number of words of Style1 between Bookmarks

I have a Word 2013 document (a script for a presentation). It had Bookmarks such as Slide1, Slide 2, Slide 3 etc.

In each section I have certain words in an 'inverted format' (dark background, white font) - say Style1.

I want to output to a CSV file a list such as this:
Bookmark Name, No of words of Style 1

Can an expert help me with the VBA for this please?
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Can you upload a small sample?
Avatar of hindersaliva

ASKER

Hi ssaqibh,

I have attached a sample.
NOTE: instead of Bookmark I am now using a Field (A sequential section marker) called 'seq slidenumber'.

As you can see, (1) has 3 words highlighted (2) has 6 and (3) has 5.

I want to have a procedure that will output this as a list (eg. a CSV) when run on any of my documents.
Thx!
Sample.docx
ASKER CERTIFIED SOLUTION
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Hi ssquibh,
It gave me, on the same Sample file ...
1 - 5 (shd be 3)
2 - 9 (shd be 6)
3 - 8 (shd be 5)
4 - 3 (shd be 0)

Looks like it's adding +3 except No 1.
Any idea why?
Thanks for your help. I'm inspired to learn Word VBA based on this small project I have. (am Excel VBA, and now can tweek PPT VBA also)
Which version of word are you using?

I am getting 3, 6, 5, 0
using 2010
I used Word 2013.
With Word 2010 I get '4120 Bad parameter'
:(
Sorry, yes it did run on Word 2010 (I think I had not updated the Fields earlier), but I still get +4 this time. I got +4 with Word 2013 when I tried second time.

Thanks for trying to get this for me.
My bad. It was so loud and clear in the title that you are using 2013 and I did not notice it. I will not be able to help you with 2013.

I am not sure why you are getting different results with 2010. I shall try changing the approach. It might take some time because word VBA is not something I use regularly.
Hey ssaquibh, thanks for persevering with it.

Yes, there's no reason why 2010 and 2013 should give different results. I also noticed that (in 2013) is was quite slow to run. Thanks for trying.

(If you like a better challenge, it is to count the words and commas and 'full stops with spaces on either side. I know, that's a strange request! I shall post as a separate question. It is so that I can get a rough time-code for the script when it's read at a particular words-per-minute (that I can control). A separate question in a few days)
Hey ssaquibh, I'm closing the question. I found another way of doing this :)
Sure. Go ahead.