Adding Autofit to window with my copy&paste Excel range to Word macro

Jbone697

New Member
Joined
Jun 7, 2018
Messages
15
This macro copies a range in excel and pastes to word, while Word opens up in landscape. I would also like it to autofit after pasting in Word. Any help would be appreciated.

Code:
[IMG]https://www.mrexcel.com/forum/newthread.php?do=postthread&f=10[/IMG]  <code>Sub PasteToWord()

    Dim wdApp As New Word.Application, wdDoc As Word.Document
    
        With wdApp
            .Visible = True
            
    Set wdDoc = .Documents.Add

        With wdDoc
        .PageSetup.Orientation = wdOrientLandscape
        Sheets("Sheet1").Range("A34:J178").Copy
    .Range.Paste
            Application.CutCopyMode = False
    
  End With
  
End With

Set wdDoc = Nothing: Set wdApp = Nothing

End Sub</code>
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hello Jbone697,

I would suggest making the essential edits in Excel before sending the data to Word. I am not sure that Excel can control Word at this level.

Oh how I miss the old Camera tool in Excel.

Hope this helps.
 
Upvote 0
It can control it at this level. I figured it out myself.

Code:
'Copy template and open in Word with landscape view
Sub PasteToWord()
    Dim wdApp As New Word.Application, wdDoc As Word.Document
    
        With wdApp
            .Visible = True
            
    Set wdDoc = .Documents.Add
        With wdDoc
        .PageSetup.Orientation = wdOrientLandscape
        Sheets("Sheet1").Range("A34:J178").Copy
    .Range.Paste
            Application.CutCopyMode = False
  
End With

'Autofit Table so it fits inside Word Document
  Set WordTable = wdDoc.Tables(1)
            WordTable.AutoFitBehavior (wdAutoFitWindow)

End With

Set wdDoc = Nothing: Set wdApp = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,454
Messages
6,178,766
Members
452,875
Latest member
Disastrouscoder

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