#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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] |
#3
|
|||
|
|||
Yhouhou!!!!!!
Works pertect! Thanks so much Macropod |
#4
|
||||
|
||||
Your task now is to figure it out ...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
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] |
#7
|
|||
|
|||
Ok,
Understanding Char ! missed me. I promise, I'll somehow get it!!! Thanks a lot Macropod |
#8
|
|||
|
|||
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 |
#9
|
|||
|
|||
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 |
#10
|
||||
|
||||
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] |
#11
|
|||
|
|||
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 |
#12
|
||||
|
||||
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] |
#13
|
|||
|
|||
'Move to start of document
Selection.HomeKey Unit:=wdStory And I need to run this Macro only once. |
#14
|
||||
|
||||
You're still working with selections, though - your next meaningful step is:
Selection.EndKey Unit:=wdLine, Extend:=wdExtend Quote:
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] |
#15
|
|||
|
|||
Macropro, I've Sent a PM
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Need help on Macro 03- Find text - if text is blank then remove line | simpleonline1234 | Word VBA | 1 | 02-25-2011 02:28 AM |
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 |