VBA code for Excel to Word copying problem

mangodango

New Member
Joined
Aug 8, 2017
Messages
9
Hello, I was thinking about the VBA macro for exporting a range from Excel to Word document. Following macro seems to be doing it, although I have a problem with the pasted size. The data copied from Excel is too big for a Word document. Is there any way to adjust the copy/paste size, so copied Excel range would fit into the doc?


Many thanks for your insights.


Code:
Sub export_excel_to_word()    Set obj = CreateObject("Word.Application")
    obj.Visible = True
    Set newobj = obj.Documents.Add
    ActiveSheet.UsedRange.Copy
    newobj.Range.Paste
    Application.CutCopyMode = False
    obj.Activate
    newobj.SaveAs Filename:=Application.ActiveWorkbook.Path & "\" & ActiveSheet.Name
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Well, you might start by limiting the scope of what you're copying; otherwise you might try a different paste method. Word supports:
.Paste
.PasteAndFormat
.PasteAppendTable
.PasteAsNestedTable
.PasteExcelTable
.PasteSpecial
any of which might (or might not) be suitable for your situation. Some of those methods take a variety of arguments, too, and some might still necessitate changes to the table's paragraph formatting post-paste. Word tables also have three autofit options you could apply post-paste.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,686
Messages
6,173,829
Members
452,535
Latest member
berdex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top