Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Adding a number to a sequence of lines ...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Smokin - 05 Nov 2005 02:49 GMT
I have a need to append a number to an instrument definition file
according to this scheme:

Original file contains many entries like this

[ Bank 115]
4=PolarisEP ;Regular
5=ModernEP ;Regular
7=PhaseClavi ;Regular
16=DrawbarOrg2 ;Regular
17=MellowDraw ;Regular

for each line that contains  "<number>=" I need to add one to the
number and place it after the "=" sign so it looks like this:  

<number>=<number + 1><space> something

Then from my example the resulting file would look like this:

[ Bank 115]
4=5 PolarisEP ;Regular
5=6 ModernEP ;Regular
7=8 PhaseClavi ;Regular
16=17 DrawbarOrg2 ;Regular
17=18 MellowDraw ;Regular

This gives me the computers patch number as well as my data list
number for easy reference, if you were curious.  The computer counts
up from 0, the data list from 1.  I would spend a lot of time manually
changing the contents of my file otherwise, so if you could assist me
with a macro (word 2003) I would be very appreciative!

This is similar to an earlier request,  for which a suggested  vba
macro was offered, and it worked very well for subtracting one from
the data list number to get the computer number.  Thanks for that ...
but it turns out I also needed the data list number (wouldn't you just
know!)
Greg Maxey - 05 Nov 2005 03:06 GMT
Try:
Sub ScratchMacro()
Dim findText As String
Dim myRange As Range
Dim i As Long
Set myRange = ActiveDocument.Range
findText = "([0-9]{1,}=)"
With myRange.Find
  .Text = findText
  .MatchWildcards = True
  While .Execute
     i = (Left(myRange, Len(myRange) - 1)) + 1
     myRange.Text = myRange.Text & i
     myRange.Collapse Direction:=wdCollapseEnd
  Wend
End With
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> I have a need to append a number to an instrument definition file
> according to this scheme:
[quoted text clipped - 33 lines]
> but it turns out I also needed the data list number (wouldn't you just
> know!)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.