Consulting

Results 1 to 2 of 2

Thread: VBA for copy paste

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jul 2021
    Posts
    1
    Location

    VBA for copy paste

    Hi,
    I don't know if this is the right place or not but I'll ask anyway.
    If not, please redirect me.

    I had a macro where I could paste the copied content within the cell table of word without losing format.
    I used that for pasting the contents from pdf to word as it removed the paragraph as well.

    I cant use the Ctrl+h option as I have only up, down and all option over there. Can't do only within the cell.
    I found few macros online but they are changed the entire document.
    If I had selected multiple cells before running the macro, it was merging it before pasting (this is not so important but good to have).

    It was only 5 or 6 line marco.

    Is it possible to get similar macro?
    This could be available somewhere here in this site but I'm new here and don't know how to use search option properly.


    Thanks in advance.

  2. #2
    I am not sure why you cannot simply use the paste tools provided on the ribbon, but how about
    Sub MyPaste()
    Dim oRng As Range
    Dim i As Integer
        If Selection.Information(wdWithInTable) = False Then
            MsgBox "Cursor is not in a table", vbCritical
            Exit Sub
        End If
        Set oRng = Selection.Range
        If oRng.Cells.Count > 1 Then
            Set oRng = oRng.Cells(1).Range
        End If
        oRng.PasteAndFormat wdFormatOriginalFormatting
    lbl_Exit:
        Set oRng = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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