> I needed to declare myRange and WordCount - perhaps you are on a more advanced version of VB than I am? I think it's just a matter of whether you have the Require Variable Declaration option ticked in Tools > Options... in the VBE. But don't untick it!! Or you'll be setting yourself up for all kinds of errors creeping in. Howard On 22 December 2010 16:02, Elizabeth Fullerton < Elizabeth_Fullerton@xxxxxxxxxxx> wrote: > Fantastic! I was fiddling around with ranges and not quite getting it > right. > > I needed to declare myRange and WordCount - perhaps you are on a more > advanced version of VB than I am? > > Now Bill can help his authors control themselves, and cut them off at the > knees if they don't! > > > > Regards > > Elizabeth Fullerton, CBAP > Lead Consultant > Infosys Australia > Ph: +61 3 9680 2000 > Fax: +61 3 9860 2999 > www.infosys.com<http://www.infosys.com> > Powered by intellect > Driven by values > > ________________________________ > From: austechwriter-bounce@xxxxxxxxxxxxx [ > austechwriter-bounce@xxxxxxxxxxxxx] On Behalf Of Neil Maloney [ > maloneyn@xxxxxxxxxxx] > Sent: Wednesday, 22 December 2010 3:56 PM > To: austechwriter@xxxxxxxxxxxxx > Subject: atw: Re: Limiting word count > > Can't use Words.Count for a selection because it counts punctuation and > paragraph marks, and there's no option to turn that off, so I had to use > ComputeStatistics, here it is ... > > > Sub Delete_After_200_Words() > > Selection.HomeKey Unit:=wdStory > > LoopIt: > > Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend > Set myRange = Selection.Range > WordCount = myRange.ComputeStatistics(Statistic:=wdStatisticWords) > > If WordCount = 200 Then > Selection.Collapse Direction:=wdCollapseEnd > Selection.Extend > Selection.EndKey Unit:=wdStory, Extend:=wdExtend > Selection.Delete > Else > GoTo LoopIt > End If > > 'This line just returns the cursor to the top of the document. > Selection.HomeKey Unit:=wdStory > > End Sub > > > Neil. > > On 22/12/2010 2:31 PM, Elizabeth Fullerton wrote: > > Of course, the next challenge is to create a macro that will delete > everything after the 200th word... > > > ************************************************** To view the > austechwriter archives, go to www.freelists.org/archives/austechwriter To > unsubscribe, send a message to austechwriter-request@xxxxxxxxxxxxx with > "unsubscribe" in the Subject field (without quotes). To manage your > subscription (e.g., set and unset DIGEST and VACATION modes) go to > www.freelists.org/list/austechwriter To contact the list administrator, > send a message to > austechwriter-admins@xxxxxxxxxxxxx************************************************** > > **************** CAUTION - Disclaimer ***************** > This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended > solely > for the use of the addressee(s). If you are not the intended recipient, > please > notify the sender by e-mail and delete the original message. Further, you > are not > to copy, disclose, or distribute this e-mail or its contents to any other > person and > any such actions are unlawful. This e-mail may contain viruses. Infosys has > taken > every reasonable precaution to minimize this risk, but is not liable for > any damage > you may sustain as a result of any virus in this e-mail. You should carry > out your > own virus checks before opening the e-mail or attachment. Infosys reserves > the > right to monitor and review the content of all messages sent to or from > this e-mail > address. Messages sent to or from this e-mail address may be stored on the > Infosys e-mail system. > ***INFOSYS******** End of Disclaimer ********INFOSYS*** > ************************************************** > To view the austechwriter archives, go to > www.freelists.org/archives/austechwriter > > To unsubscribe, send a message to austechwriter-request@xxxxxxxxxxxxx with > "unsubscribe" in the Subject field (without quotes). > > To manage your subscription (e.g., set and unset DIGEST and VACATION modes) > go to www.freelists.org/list/austechwriter > > To contact the list administrator, send a message to > austechwriter-admins@xxxxxxxxxxxxx > ************************************************** >