PDA

View Full Version : VBA for copy paste



Vinayak
07-20-2021, 09:26 AM
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.

gmayor
07-20-2021, 09:33 PM
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