Excel to Word Formating + Customisable Table copy and paste

waltermelonwong

New Member
Joined
Jun 11, 2018
Messages
3
Background information: I work with lots of products that require contracts where the contracts are largely similar but may have different fields have and different language required. I'm trying to automate this entire process where I have a main "Inputs" Page and based on what I check and fill up, it will build the perfect contract for me and convert it to word document from excel when I click a "generate' button.

How I've approached this: I've created a "Master" sheet where it has all the different languages and parts of the contract I require. By filling up the blanks in the "Input" page it will change the languages for all cases accordingly. Then based on what I check on the "Input" page. It will copy and paste the portions that I want into a "Print" page where the perfect contract is made. I've written it such that it will copy to the last row since the contract length may vary according to the number of fields filled up. After that, when I click on the generate button and it will convert the perfect page to a word document.

Problem I'm facing:
1. When it converts to word document, I open up a template that I have and it works fine. However, the paragraph and line spacing is horrible and I have no idea how to fix it. I have no knowledge in coding and I've managed to make it work by googling and grabbing bits and pieces from everywhere.
I need the "table" I'm copying from excel to fit into the word document and have a larger spacing between each row. Also in my documents certain rows are merged to form bigger boxes but it doesn't always reflect on the word document (for those whose texts are shorter).

2. I need to insert a filled table depending on the length of the contract. The filled table is in a different sheet called "Table". If it's ten years I need it to copy up to 10 rows of the filled table, if its 20 I need it to copy the first 20 rows and paste it into a certain Section in the contract under the "Print".

Please find below what I've used for both problems.


Code:
[B]PROBLEM 1:[/B]
Sub Generate()
 'Dec 19, 2015
If MsgBox("Confirm All Details Are Correct?", vbOKCancel, "from Excel to Word") = vbCancel Then Exit Sub
Sheets("Print").Select

On Error Resume Next
Dim objWord
Dim objDoc
Dim a As Integer
 Set objWord = CreateObject("Word.Application")
 Set objDoc = objWord.Documents.Open("CENSORED DOCUMENT.docx")
 objDoc.Visible.True
 If objDoc Is Nothing Then
 Set objDoc = CreateObject("Word.Application")
 End If
 objDoc1.Visible = True
 Set objDoc = objDoc.Documents.Add
 a = Sheets("Print").Range("A" & Rows.Count).End(xlUp).Row
 Sheets("Print").Range("A1:B" & a).Copy
 objDoc.Range.PasteExcelTable False, False, True
 objDoc.Activate
 objDoc.Tables(1).AutoFitBehavior wdAutoFitContent
 Application.CutCopyMode = False
 On Error GoTo 0
 
 End Sub
[B]
PROBLEM 2:

[/B]Sub contract()
If Not IsEmpty(Sheets("MASTER INPUTS").Range("$C$3")) Then
    Sheets("MASTER").Rows("1:13").Copy Destination:=Sheets("Print").Range("A" & Cells(Rows.Count, 1).End(xlUp).Row)

End If

If Sheets("MASTER INPUTS").Range("$C$20").Value = "Fixed" And Range("$C$21").Value = "No Strike" Then
    Sheets("MASTER").Rows("21:26").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

ElseIf Sheets("MASTER INPUTS").Range("$C$20").Value = "Fixed" And Range("$C$21").Value = "Strike" Then
    Sheets("MASTER").Rows("28:34").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

ElseIf Sheets("MASTER INPUTS").Range("$C$20").Value = "Floating" Then
    Sheets("MASTER").Rows("36:46").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

End If

If Sheets("MASTER INPUTS").Range("$C$36").Value = "Amortization" Then
    Sheets("MASTER").Rows("48:53").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
ElseIf Sheets("MASTER INPUTS").Range("$C$36").Value = "Redemption" Then
    Sheets("MASTER").Rows("55:57").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
End If


[B]>>> I need the customizable table to be added into this part here from sheet "Table" if not the contract format in the "Print" page will be wrong. [/B]


If Not IsEmpty(Sheets("MASTER INPUTS").Range("$C$3")) Then
    Sheets("MASTER").Rows("59:73").Copy Destination:=Sheets("Print").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
End If
 
End Sub




PLEASE SAVE ME. THANK YOU !
 
Last edited by a moderator:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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