Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-10-2013, 10:15 PM
bpanda bpanda is offline Word Count Macro Mac OS X Word Count Macro Office for Mac 2011
Novice
Word Count Macro
 
Join Date: Jan 2013
Posts: 3
bpanda is on a distinguished road
Default Word Count Macro

I got this Word Count macro that I copied from somewhere. It works very well but I have forgotten how it works. All I remember is that it appears to count the number of words in a section or in a part of a section. I have a bookmark called abstract that it uses to identify where to start or stop counting. Can anyone figure this out?



Code:
Sub AbstractWordCount()
'
' AbstractWordCount Macro
'
'
Dim oRange As Word.Range
Dim sBookmarkName As String
Dim sTemp As String
 
sBookmarkName = "abstract"
With ActiveDocument
  sTemp = " " + Format(.Sections(3).Range.Words.Count, "0")
  Set oRange = .Bookmarks(sBookmarkName).Range
  oRange.Delete
  oRange.InsertAfter Text:=sTemp
  .Bookmarks.Add Name:=sBookmarkName, Range:=oRange
End With
 
End Sub

Last edited by macropod; 01-29-2013 at 08:45 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 01-11-2013, 06:51 PM
fumei fumei is offline Word Count Macro Windows 7 64bit Word Count Macro Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

" I have a bookmark called abstract that it uses to identify where to start or stop counting."

Oh no it does not. There is no identification of where to start or stop counting.

The code is very explicit. The existing bookmark "abstract" is replaced by the word count of Section 3. No more, no less. Please note that if there is no existing bookmark "abstract", or there is no Section 3, the code will error out.

If I may, if you copy code from someplace, and it does not have comments, add your own. First of all it will make you understand things more. Second, comments generally make things understandable.


Code:
Sub AbstractWordCount()
'
' AbstractWordCount Macro
'
'
Dim oRange As Word.Range
Dim sBookmarkName As String
Dim sTemp As String
' make the string variable sTemp = "abstract"
sBookmarkName = "abstract"
With ActiveDocument
  ' make the string variable sTemp = the word count of Section 3
  sTemp = " " + Format(.Sections(3).Range.Words.Count, "0")
 
  ' set the range object to be the bookmark "abstract"
  Set oRange = .Bookmarks(sBookmarkName).Range
 
  ' delete the bookmark range
  oRange.Delete
 
  ' insert the value of sTemp (i.e. the word count of Section 3)
  oRange.InsertAfter Text:=sTemp
 
  ' make that a bookmark "abstract"
  .Bookmarks.Add Name:=sBookmarkName, Range:=oRange
End With
End Sub

Last edited by macropod; 01-29-2013 at 08:46 PM. Reason: Added code tags & formatting
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word count question Wuffybrother Word 3 03-22-2019 03:40 AM
Word Count Macro Where did live word count go? Tango Mike Word 3 08-01-2012 09:34 PM
Word Count Macro Word Count in Excel dallas Excel 1 11-23-2011 09:20 AM
*Word 2007 Macro for Character Count gbartlet Word 0 07-21-2010 11:12 AM
changing word count hamster Word 3 06-03-2010 01:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:11 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft