Using a Macro to Cut and Paste 
Author Message
 Using a Macro to Cut and Paste

Hi All

I'm trying to move a block of text which is in a square created by
exclamation marks and dashes, I want to cut it out and move it down 2 lines,
the blocks of text occur every few (random number) of lines within the
document.  I'm not having any success recording the macro.  Can anyone help
please?

TIA

Wendy



Wed, 21 Apr 2004 03:37:39 GMT  
 Using a Macro to Cut and Paste
Wendy,

Recording a macro directly is always a little sticky when you're doing a
non-simple Find operation.  But if you'll post an excerpt of exactly what
the 'square' looks like, someone can probably give you the code to do what
you want.


-- See the MVP FAQ at http://www.mvps.org/word --------------------------
----------------- "Life is nothing if you're not obsessed." --John Waters
-------------------------------------------------------------------------
Please reply only to the newsgroup.

Quote:

> Hi All

> I'm trying to move a block of text which is in a square created by
> exclamation marks and dashes, I want to cut it out and move it down 2 lines,
> the blocks of text occur every few (random number) of lines within the
> document.  I'm not having any success recording the macro.  Can anyone help
> please?

> TIA

> Wendy



Thu, 22 Apr 2004 19:48:16 GMT  
 Using a Macro to Cut and Paste
Hi All

Copy of 'square' below, I've had to take out loads of spaces to make
it fit this page.
TIA

Wendy

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!/01                                  LINE 1                        !
!                                     LINE 2                        !
!    D.O.B. 00/00/0000                LINE 3                        !
!                                     LINE 4                        !
!    (37 spaces to 'line')                     (24 spaces)          !
!                                     POSTCODE                      !
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



Fri, 23 Apr 2004 22:36:28 GMT  
 Using a Macro to Cut and Paste
Is there ever anything after the last exclamation point? If the entire line
is cut, are you going to get any extra text? If your answer is yes, is there
either a fixed number of characters to be copied or is there anything
keeping exclamation points from being included it the data or in the area
following the second marker?

Are there always the same number of lines?

What is at the end of each line? You'll need to turn on "Show All" in the
View options to see. It should be either a paragraph mark or a manual line
break. The paragraph mark is a pillcrow (sort of a double backwards P) and
the line break is a bent arrow.

What is at the end of each of the two lines that follow the block you want
to move?

Where is this text coming from?

Answers to the above would help me if I were writing a macro to do what you
want.

--
Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://www.addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
 --------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.


Quote:
> Hi All

> Copy of 'square' below, I've had to take out loads of spaces to make
> it fit this page.
> TIA

> Wendy

>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> !/01                                  LINE 1                        !
> !                                     LINE 2                        !
> !    D.O.B. 00/00/0000                LINE 3                        !
> !                                     LINE 4                        !
> !    (37 spaces to 'line')                     (24 spaces)          !
> !                                     POSTCODE                      !
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



Sat, 24 Apr 2004 00:43:39 GMT  
 Using a Macro to Cut and Paste
Hi Wendy,

OK, try something like this (editing the hyphens to match the reality,
of course).  Also, obviously, this assumes that the string I've shown
in the .Text line below occurs uniquely in those boxes and nowhere else.

Sub foo()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
   .Text = "- - - - - - - - - - - - - - - - - - [etc] - - - - - -^p!/01"
   .Replacement.Text = ""
   .Forward = True
   .Wrap = wdFindStop
   .Format = False
   .MatchWildcards = False
   Do While .Execute
   With Selection
      .EndKey wdLine, wdExtend
      .MoveDown wdLine, 6, wdExtend
      .Cut
      .MoveDown wdLine, 2
      .Paste                        '<----------see note below
   End With
   Loop
End With
End Sub

Note: If these squares appear in the midst of text that *wraps* --
that is, text that *doesn't* have paragraph marks at its line endings,
you'll want to place the line

     .TypeParagraph

where shown above (just before .Paste).  Otherwise the first few
characters of your pasted text could "land" at the right-hand end
of the text that precedes it rather than at the left margin.

Hope this helps.


-- See the MVP FAQ at http://www.mvps.org/word ------------------------
--------------- "Life is nothing if you're not obsessed." --John Waters
-----------------------------------------------------------------------
Please reply only to the newsgroup.

Quote:

> Hi All

> Copy of 'square' below, I've had to take out loads of spaces to make
> it fit this page.
> TIA

> Wendy

>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> !/01                                  LINE 1                        !
> !                                     LINE 2                        !
> !    D.O.B. 00/00/0000                LINE 3                        !
> !                                     LINE 4                        !
> !    (37 spaces to 'line')                     (24 spaces)          !
> !                                     POSTCODE                      !
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



Sat, 24 Apr 2004 01:17:10 GMT  
 Using a Macro to Cut and Paste
Hi Wendy,

In the example you posted, the box started with a non-breaking space, and
all lines except for the last ended in manual line breaks. You could use
these facts to select the box with the following *wildcard* search:
^0160\-*^13

(^0160 is the non-breaking space, \- is a hyphen, * will match any text, and
^13 is a paragraph mark.)

You can then cut the box, move two lines down, and paste, which should be
easy to record with the macro recorder.

Greetings, Klaus



Sat, 24 Apr 2004 02:41:21 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Macro: Search, Cut, Paste Hidden Text

2. Cut and paste using richtext?

3. Cutting and Pasting using Visual Basic 3.0 Pro

4. Cut/paste from a text file using FSO

5. Cut and paste using richtext?

6. Macros using Paste Special and In Line

7. Pasting within a protected document using a macro

8. Cut and paste code

9. Cut, Copy, Paste

10. How can I copy records like cut-n-paste

11. disabling cut/copy/paste

12. Handling cut and paste through VBa

 

 
Powered by phpBB® Forum Software