Excel VBA sheet to word autofit

excel_learnerz

Board Regular
Joined
Dec 12, 2018
Messages
73
Hello
With the below code I can export used ranged as table into Microsoft word.
When it goes to word the table isn't autofitted, so half of it is not appearing correctly.
Is there a way for it to be formatted correctly in the word document
Thanks in advance


Sub annex()
With Sheets("Sheet1").Select
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:="C:\temp" & ActiveSheet.Name
End With
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hello
With the below code I can export used ranged as table into Microsoft word.
When it goes to word the table isn't autofitted, so half of it is not appearing correctly.
Is there a way for it to be formatted correctly in the word document
That all depends on what you mean by 'formatted correctly'. Try one of:
newObj.Range.PasteExcelTable False, False, False
newObj.Range.PasteAndFormat 16 'wdFormatOriginalFormatting
newObj.Range.PasteAndFormat 19 'wdUseDestinationStylesRecovery
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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