Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2012, 10:47 AM
macropod's Avatar
macropod macropod is offline how to know word number by VBA Windows 7 64bit how to know word number by VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Simpler:
Code:
Sub Demo()
With ActiveDocument
  MsgBox .Range(0, InStr(.Range.Text, "My String")).ComputeStatistics(wdStatisticWords) - 1
End With
End Sub

__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 08-13-2012, 08:48 PM
Venky62 Venky62 is offline how to know word number by VBA Windows 7 64bit how to know word number by VBA Office 2010 32bit
Advanced Beginner
 
Join Date: Jul 2012
Posts: 58
Venky62 is on a distinguished road
Default

Great macro, Paul, as always.

While testing the code I wrote and the one you posted, I found that my code gives wrong results. If the number of words before the search string is 4, then my code gives 5. If the number is 25, it gives 27. And the margin of error increases, with increasing number of words before the search string.Your code, on the other hand, is perfect.

What is it that I am doing wrong? Thanks in advance.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to know word number by VBA generating a number in Word John P Word 1 05-31-2012 10:29 PM
how to know word number by VBA auto number in word expert4knowledge Word 7 05-31-2012 02:37 PM
how to know word number by VBA Mailing: how to make the "page number" in Word is the same as "row number" in excel w Jamal NUMAN Word 1 09-03-2011 11:37 AM
Textbox Number changes when I open Word t0m46 Word VBA 0 09-07-2010 05:46 AM
Number formatting in Word table 8braitp Word Tables 0 08-27-2009 04:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:46 PM.


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