Consulting

Results 1 to 9 of 9

Thread: Paste from Word to Excel

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Paste from Word to Excel

    So, my table contains paragraph returns, and I want to maintain them, but paste my data to Excel.

    Anybody want to write a routine that'll:

    In Word
    Select the table in which the cursor resides (Table-Select-table)
    Find all paragraph returns (type ^p into find/replace or use that chr, I forget)
    Replace with some oddball character like the pipe
    Copy the table contents to the clipboad and wait for user to choose paste

    In Excel
    Paste
    ~Anne Troy

  2. #2
    VBAX Regular
    Joined
    May 2004
    Location
    Seattle, WA
    Posts
    24
    Location
    Here is the Word macro. Need to have the cursor in the table.

    Sub ReplaceRetsCopy()
    Selection.Tables(1).Select
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = "||"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Copy
    End Sub
    Here is the Excel macro. Paste table into Excel. Run macro. Macro assumes that the table is still selected.

    Sub InsertReturns()
    Dim str As String
    Dim cell As Range
    For Each cell In Selection
        str = cell.Value
        cell.Value = Replace(str, "||", Chr(10))
    Next
    End Sub

    You could automate this from start to end.

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Great. Word doesn't need all those FALSE thingees, so we'll chop them right out:


    Sub ReplaceRetsCopy() 
     Selection.Tables(1).Select 
     Selection.Find.ClearFormatting 
     Selection.Find.Replacement.ClearFormatting 
      With Selection.Find
        .Text = "^p"
        .Replacement.Text = "||"
        .Forward = True
        .Wrap = wdFindStop
      End With 
     Selection.Find.Execute Replace:=wdReplaceAll 
     Selection.Copy 
    End Sub 

    ~Anne Troy

  4. #4
    VBAX Regular
    Joined
    May 2004
    Location
    Seattle, WA
    Posts
    24
    Location
    I am not a Word VBA programmer. I just did the usual Macro Record trick.
    I hope this does what you want.

  5. #5
    VBAX Regular
    Joined
    May 2004
    Location
    Seattle, WA
    Posts
    24
    Location
    Side note:

    What is happening to the signatures. It shows up in the preview but not in the final post.

  6. #6
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Not sure what you mean, Cesar?
    ~Anne Troy

  7. #7
    VBAX Regular
    Joined
    May 2004
    Location
    Seattle, WA
    Posts
    24
    Location
    For the signature, I discovered that I had to allow my signature to be displayed. I had to go to the "User CP" to allow. The "Preview Option" has bug because it was showing the signature.

    Also, for the Word macro, it changes the data. If you want to keep the clean you could either add Undo to the macro or do another Find/Replace.

  8. #8
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Actually, I think that setting is whether you want to view them, not USE your signature.
    ~Anne Troy

  9. #9
    Mac Moderator VBAX Expert shades's Avatar
    Joined
    May 2004
    Location
    Kansas City, USA
    Posts
    638
    Location
    Quote Originally Posted by Dreamboat
    Great. Word doesn't need all those FALSE thingees, so we'll chop them right out:


    Sub ReplaceRetsCopy()
     Selection.Tables(1).Select
     Selection.Find.ClearFormatting
     Selection.Find.Replacement.ClearFormatting
      With Selection.Find
        .Text = "^p"
        .Replacement.Text = "||"
        .Forward = True
        .Wrap = wdFindStop
      End With
     Selection.Find.Execute Replace:=wdReplaceAll
     Selection.Copy 
    End Sub


    Just curious on the highlighted lines. Is VBA in Word like in Excel? So we can shorten the code from:

    Selection.Tables(1).Select
     Selection.Find.ClearFormatting
    to:

    Selection.Tables(1).Find.ClearFormatting

    Software: LibreOffice 3.3 on Mac OS X 10.6.5
    (retired Excel 2003 user, 3.28.2008 )
    Humanware: Older than dirt
    --------------------
    old, slow, and confused
    but at least I'm inconsistent!

    Rich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •