Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2013, 12:10 PM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default Text manipulation in MACRO

Hi folks,



I struggle with a simple task... As a I quite newbie with Word Macro, perhasp one of you got the answer.

I'm trying to transform the following text:

DP 43:29:02 N 003:50:39 E
DP 43:34:12 N 003:43:04 E
VD=+
VX=43:34:49 N 003:58:16 E
DP 43:45:45 N 003:59:56 E
DP 43:40:01 N 004:06:40 E
VD=-
VX=43:34:49 N 003:58:16 E
DP 43:29:02 N 003:50:39 E

I need to add one line after each "VX" line
This line should be build from:
"DB" + "whole 2 lines up without DP" + "," + "whole 1 line down without DP"

my aim is to get that:

DP 43:29:02 N 003:50:39 E
DP 43:34:12 N 003:43:04 E
VD=+
VX=43:34:49 N 003:58:16 E
DB 43:34:12 N 003:43:04 E,43:45:45 N 003:59:56 E
DP 43:45:45 N 003:59:56 E
DP 43:40:01 N 004:06:40 E
VD=-
VX=43:34:49 N 003:58:16 E
DB 43:40:01 N 004:06:40 E,43:29:02 N 003:50:39 E
DP 43:29:02 N 003:50:39 E

Many thanks !!!!

a picture is worth a thousand words

Reply With Quote
  #2  
Old 03-08-2013, 09:29 PM
macropod's Avatar
macropod macropod is offline Text manipulation in MACRO Windows 7 64bit Text manipulation in MACRO Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Hi srt,

You can do this without a macro, using a wildcard Find/replace, where:
Find = (DP )([!^13]{1,})([^13]VD*VX[!^13]{1,}[^13])(DP )([!^13]{1,}[^13])
Replace = \1\2\3DB \2,\5\4\5
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-09-2013, 04:19 AM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default

Yhouhou!!!!!!

Works pertect!
Thanks so much Macropod
Reply With Quote
  #4  
Old 03-09-2013, 04:53 AM
macropod's Avatar
macropod macropod is offline Text manipulation in MACRO Windows 7 64bit Text manipulation in MACRO Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Your task now is to figure it out ...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-09-2013, 04:59 AM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default

I do not wish to take a lot of your time but, as it seems dead easy for you

I'm trying to figure out wildcards but.... not yet

I want to find any word begin by : Front*... without any number following
And replace by : **French Border**

44º01’40”N,007º33’06-E
43º58’04”N,007º38’08-E
Frontièrefrancoitalienne43º47’02”N,007º31’47-E
43º45’06”N,007º26’00-E
43º45’06”N,007º16’44-E
43º38’32”N,007º00’00-E
43º37’36”N,006º55’24-E

to

44º01’40”N,007º33’06-E
43º58’04”N,007º38’08-E
**French border**
43º47’02”N,007º31’47-E
43º45’06”N,007º26’00-E
43º45’06”N,007º16’44-E
43º38’32”N,007º00’00-E
43º37’36”N,006º55’24-E


Any idea Macropod?
Thanks

Marc
Reply With Quote
  #6  
Old 03-09-2013, 05:05 AM
macropod's Avatar
macropod macropod is offline Text manipulation in MACRO Windows 7 64bit Text manipulation in MACRO Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

You can do this too with a wildcard Find/replace, where:
Find = <Front[!0-9]{1,}
Replace = **French border**^p
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 03-09-2013, 05:10 AM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default

Ok,
Understanding Char ! missed me.

I promise, I'll somehow get it!!!

Thanks a lot Macropod
Reply With Quote
  #8  
Old 03-09-2013, 02:11 PM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default

I've an other issue where wildcards can't help me....

I would like to store the value of one specific line.
For instance, the first line of one paragraph and the 4 last one.

My example in the following paragraph

CTR CHERBOURG
49º48’11”N,001º33’24”W -- 49º42’47”N,001º13’25”W --
49º35’15”N,001º15’37”W -- 49º36’11”N,001º37’58”W --
arc anti--horaire de 3,24NM de rayon centré sur
49º39’25”N,001º38’10”W -- 49º41’59”N,001º35’06”W --
49º48’11”N,001º33’24”W
D
2500ft AMSL
------------
SFC

I would like to transform my paragraph like that:

AN CTR CHERBOURG
AC D
AH 2500F AMSL
AL SFC
49º48’11”N,001º33’24”W -- 49º42’47”N,001º13’25”W --
49º35’15”N,001º15’37”W -- 49º36’11”N,001º37’58”W --
arc anti--horaire de 3,24NM de rayon centré sur
49º39’25”N,001º38’10”W -- 49º41’59”N,001º35’06”W --
49º48’11”N,001º33’24”W

And I would need to store those line as var because, I need then to performe data processing with coordinate.

Thank you for wasting you time for me.

Marc

Reply With Quote
  #9  
Old 03-10-2013, 10:18 AM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default

Hi,
I've done!
I think , I've used a sledgehammer to kill a fly. But It works.
Thanks anyway.

Marc

My code is:
Code:
Private Sub Miseenforme_Click()
'Declare variables
Dim outputStr As String
Dim line1 As String
Dim lineX As String
Dim lineX_1 As String
Dim lineX_2 As String
Dim lineX_3 As String
Dim endChar As String
Dim numOfLines As Integer
Dim rngTemp As Range
'Count the number of non blank lines in current document
numOfLines = ActiveDocument.BuiltInDocumentProperties("NUMBER OF LINES")
'Move to start of document
Selection.HomeKey Unit:=wdStory
'Move to start of line
Selection.HomeKey Unit:=wdLine
'Select entire line and copy into variable currLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
line1 = "AN " & Selection.Range.Text
Selection.Delete
Selection.MoveDown Unit:=wdLine, Count:=(numOfLines - 5)
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
lineX_3 = "AC " & Selection.Range.Text
Selection.Delete
' Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
lineX_2 = "AH " & Selection.Range.Text
Selection.Delete
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
lineX_1 = Selection.Range.Text
Selection.Delete
' Selection.MoveDown Unit:=wdLine, Count:=2
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
lineX = "AL " & Selection.Range.Text
Selection.Delete
'past line1 + AN
Set rngTemp = ActiveDocument.Range(Start:=0, End:=0)
With rngTemp
  .InsertBefore line1
  .InsertAfter lineX_3
  .InsertAfter lineX_2
  .InsertAfter lineX
End With
End Sub

Last edited by macropod; 03-10-2013 at 06:23 PM. Reason: Added code tags & formatting
Reply With Quote
  #10  
Old 03-10-2013, 01:30 PM
macropod's Avatar
macropod macropod is offline Text manipulation in MACRO Windows 7 64bit Text manipulation in MACRO Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Oh, you mean like:
Find = (CTR[!^13]@^13)(*^13)([!^13]^13)([!^13]@^13)[!^13]@^13([!^13]@^13)
Replace = AN \1AC \3AH \4AL \5\2

PS: I might have replied sooner, but I didn't see your penultimate post till a short while ago.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 03-10-2013, 01:43 PM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default

Hey,
No cause i can't predict the first line content "CRT" here but can be anything
Furthermore, I need to put those 4 lines at the beginning of paragraph

That why, I think need to store each line...

I guess, A simpler way is possible but a got one
Reply With Quote
  #12  
Old 03-10-2013, 01:48 PM
macropod's Avatar
macropod macropod is offline Text manipulation in MACRO Windows 7 64bit Text manipulation in MACRO Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

The question then becomes:
How do you identify the first line without selecting it? Your macro pre-supposes the line is selected, which means you can't process more than one at a time.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 03-10-2013, 02:40 PM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default

'Move to start of document
Selection.HomeKey Unit:=wdStory

And I need to run this Macro only once.
Reply With Quote
  #14  
Old 03-10-2013, 02:56 PM
macropod's Avatar
macropod macropod is offline Text manipulation in MACRO Windows 7 64bit Text manipulation in MACRO Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

You're still working with selections, though - your next meaningful step is:
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Quote:
And I need to run this Macro only once.
It seems to me that writing the macro would've taken much longer than doing the job manually. Unless you need to do this on multiple documents, there'd be a negative ROI.

That said, you can still do it with Find/Replace, by deleting the 'CTR', though typing the expression each time might be tedious - as well as being error-prone. As a macro, the F/R becomes:
Code:
Sub Demo()
With Selection
  .HomeKey Unit:=wdStory
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "([!^13]@^13)(*^13)([!^13]^13)([!^13]@^13)[!^13]@^13([!^13]@^13)"
    .Replacement.Text = "AN \1AC \3AH \4AL \5\2"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceOne
  End With
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 03-10-2013, 04:20 PM
srt srt is offline Text manipulation in MACRO Windows 8 Text manipulation in MACRO Office 2010 64bit
Novice
Text manipulation in MACRO
 
Join Date: Mar 2013
Location: Glasgow, UK
Posts: 15
srt is on a distinguished road
Default

Macropro, I've Sent a PM
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Text manipulation in MACRO Macro to find text and replace with form field containing that text iiiiifffff Word VBA 16 06-04-2016 01:47 AM
Macro to find text in between two characters and then format selected text? qcom Word 5 02-19-2015 11:23 PM
Text manipulation in MACRO Need help on Macro 03- Find text - if text is blank then remove line simpleonline1234 Word VBA 1 02-25-2011 02:28 AM
Text manipulation in MACRO Combobox manipulation vsempoux Word VBA 3 10-31-2009 08:58 AM
Mail merge Field Code Manipulation macjnr Mail Merge 0 09-10-2009 11:37 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:12 AM.


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