Excel to Word to be Landscape

petars87

New Member
Joined
Sep 14, 2016
Messages
49
Hi people,
can u help me to I change Word to be Landscape

Code:
 Sub CopyToWord()
     Dim objWord As Object
     Dim objDoc As Object
     Set objWord = CreateObject("Word.Application")
     Set objDoc = objWord.Documents.Add(Template:= _
         "C:\XXX\Desktop\template.docx")
         
     Set Ar = Worksheets("Sheet1").Range("A1:F" & Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
    
     Ar.Copy
     
     objDoc.Range.Paste
    
    
With objDoc
    .PageSetup.Orientation = wdOrientLandscape
    End With
     
     objWord.Visible = True
     Set objDoc = Nothing
     Set objWord = Nothing
 End Sub

Thank you.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
To use named constants with late binding, you need to tell your code what their values are. For example:
Code:
Sub CopyToWord()
Dim objWord As Object, objDoc As Object
Const wdOrientPortrait As Long = 0
Const wdOrientLandscape As Long = 1
Set objWord = CreateObject("Word.Application")
With objWord
  Set objDoc = .Documents.Add(Template:="C:\XXX\Desktop\template.docx")
         
  With Worksheets("Sheet1")
    .Range("A1:F" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy
  End With
     
  With objDoc
    .Range.Paste
    .PageSetup.Orientation = wdOrientLandscape
  End With
     
  .Visible = True
End With
Set objDoc = Nothing: Set objWord = Nothing
End Sub
Better still would be to use a template that already had the desired orientation - then you wouldn't have to change it in code.
 
Last edited:
Upvote 0
Thank you Macropod, it works nice, u saved my time..

Can u help me with one more question please:

How to, in this code add part to insert PageBrake after word "Name"
 
Upvote 0
There's no indication in anything you've posted regarding "Name", so it's far from obvious how that should be addressed. You will need to give more details.

PS: It's midnight here, so I won't be replying for ~8hrs.
 
Upvote 0
That word is in this range

Code:
With Worksheets("Sheet1")
    .Range("A1:F" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy
  End With
 
Upvote 0
Plese don't spend time on this, I posted again.
Please continue in this thread, as that thread has been locked, as per forum rules.
 
Upvote 0
That word is in this range

Code:
With Worksheets("Sheet1")
    .Range("A1:F" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy
  End With
So what do you want to do - split the table or just make sure the rows don't get split across a page break? Do you realize that, if you split the table, any header rows in your data won't appear on the new table whereas, without splitting the table, Word's 'repeat header rows' function can make the table header appear on all pages the table spans? Does the word 'Name' appear more than once in the table? If so, how is a macro to determine which instance to use? Is the word 'Name' at the start or end of a row, or is somewhere along the row? If it's at the start or somewhere along the row, do you want to split the table at that point, or at the end of the row?
 
Upvote 0

Forum statistics

Threads
1,223,803
Messages
6,174,687
Members
452,577
Latest member
Filipzgela

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