Forum

How to copy varying...
 
Notifications
Clear all

How to copy varying table range in excel and paste it in word as picture

2 Posts
2 Users
0 Reactions
81 Views
(@sammy765)
Posts: 1
New Member
Topic starter
 

I'm trying to write a code to copy varying range from excel as picture and paste it in word. Everything is working smooth but my table range is varying which vba is not capturing. Its capturing only fixed range.

 

Sheets ("Sheet2").Select
Set exWb =ThisWorkbook
Set tbl - exWb.Sheets ("Sheet5").Range ("F8:K25")
tbl.CopyPicture

Truly appreciate anykind of help

 
Posted : 10/04/2020 5:23 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Sammy,

Without seeing your workbook I can't give you my 'best' answer.  I don't know what data you are trying to copy.

Perhaps you could format your data in a table and copy the table using the table name, or you could click into a cell in the range before running your macro and then copy it using ActiveCell.CurrentRegion.

 

Option Explicit

Sub CopyRangePic()

Dim tbl As Range
Dim exWB As Workbook
Dim Dest As Worksheet

Set Dest = ThisWorkbook.Sheets(2)

'Must first click into range you want to copy
ActiveCell.CurrentRegion.Select
Set tbl = Selection
tbl.CopyPicture
Dest.Paste

End Sub

 

Sub CopyTablePic()

Dim tbl As Range
Dim exWB As Workbook
Dim Dest As Worksheet

Set Dest = ThisWorkbook.Sheets(2)

Set tbl = Range("Table1")
tbl.CopyPicture
Dest.Paste

End Sub

 

Please see attached workbook for examples of both.

Regards

Phil

 
Posted : 10/04/2020 11:22 pm
Share: