Convert Excel Sheets to Word and Fit to Window

sabbuck

New Member
Joined
Aug 21, 2017
Messages
24
I have an excel workbook with 13 active sheets. I have a button to convert 5 of these sheets to word, which works fine (see code). I'm trying to get the word document to fit to window when the data is converted. And also if I can get the word document to be landscape. Both of these can be done manually of course, but I'm trying to avoid as much manual work as I can for the users of these documents. Any help is much appreciated.

VBA Code:
Sub Open_Word_Document()
Dim wdApp As Word.Application, wdDoc As Word.Document, sh As Worksheet
Application.ScreenUpdating = False
Application.StatusBar = "Creating new document..."
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
For Each sh In ActiveWorkbook.Worksheets
  Select Case sh.Name
    Case Is = "Membership 1", "Product & Services 1", "Geographical 1", "Transaction 1", "Distribution 1"
    Application.StatusBar = "Copying data from " & sh.Name & "Sheets"
    sh.UsedRange.Copy
    wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Paste
    Application.CutCopyMode = False
  End Select
Next sh
Set sh = Nothing
Application.StatusBar = "Cleaning up..."
With wdApp.ActiveWindow
    If .View.SplitSpecial = wdPaneNone Then
        .ActivePane.View.Type = wdPrintView
    Else
        .View.Type = wdNormalView
    End If
End With
Set wdDoc = Nothing
wdApp.Visible = True
Set wdApp = Nothing
Application.StatusBar = False
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi sabbuck. Maybe you can trial/adapt this bit of code to your needs. Not sure about the landscape needs. HTH. Dave
Code:
'determine width
With WdApp.ActiveDocument.PageSetup
    WidthAvail = .PageWidth - .LeftMargin - .RightMargin
End With
'loop sheets
For Each Ws In ActiveWorkbook.Worksheets
Cnt = Cnt + 1
Application.StatusBar = "Copying data from " & Ws.Name & "..."
Ws.UsedRange.Copy
WdDoc.Paragraphs(WdDoc.Paragraphs.Count).Range.PasteSpecial DataType:=3 '9  '4
'size range to sheet
With WdDoc.Shapes(Cnt)
.LockAspectRatio = msoFalse
.Width = WidthAvail
End With
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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