EXCEL VBA to create contract

AawwYeahh

New Member
Joined
Aug 10, 2017
Messages
37
I am attempting to create a user contract that customer can sign and date only.
I have tried (unsuccessfully) to create as worksheet and export to locked .docx
My newest attempt is to create .dotx template (In Word) and have bookmarked the 7 items I need from worksheet "Contract"
If I open word and select file I can manage to populate said word template
Then manually restrict editing and save as correct name.

I currently have VBA in EXCEL that will create Folder/File name based on cell value
ideally I would like to create document (locked with signature and date line being only editable selections) in named Folder and File
My first attempt was to create contract in excel and export to .docx BUT no matter what I tried entire document remained editable (not just signature and date line)

I am open to any suggestions at this point!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I have tried this code for a mail merge concept (with limited sucess
VBA Code:
Sub ExportButton()
Const FilePath As String = "C:\MidSouth\Administrative\[Custom Forms]\"
Dim wd As New Word.Application
Dim doc As Word.Documents
wd.Visible = True

Dim Name As String
Dim Address As String
Dim City As String
Dim State As String
Dim Deposit As String
Dim Balance As String
Dim State2 As String
Dim Name2 As String

ThisWorkbook.Sheets("Contract").Select
Name = .Range("A2").Value 'value from sheet1
Address = .Range("B2").Value
City = ThisWorkbook.Sheets("Contract").Range("C2").Value
State = ThisWorkbook.Sheets("Contract").Range("D2").Value
Deposit = ThisWorkbook.Sheets("Contract").Range("E2").Value
Balance = ThisWorkbook.Sheets("Contract").Range("F2").Value
State2 = ThisWorkbook.Sheets("Contract").Range("D2").Value
Name2 = ThisWorkbook.Sheets("Contract").Range("A2").Value

Set doc = wd.Documents.Open(FilePath & "Contract.dotx")
Copy2word "ClientField", Name
Copy2word "ClientAddressField", Address
Copy2word "ClientCityField", City
Copy2word "ClientSTField", State
Copy2word "ClientDEPField", Deposit
Copy2word "ClientBalField", Balance
Copy2word "ClientST2Field", State2
Copy2word "Client2Field", Name2

doc.Close

wd.Quit
'MsgBox "Created files in " & FilePath & "!"

End Sub
 
Upvote 0
And this code for a excel based contract (.docx remains editable)
VBA Code:
Sub CreateWordReport()
Dim wordApp As New Word.Application, wordDoc As New Word.Document, xlSht As Excel.Worksheet
Set xlSht = ActiveWorkbook.Sheets("Contract2")
With wordApp
  .Visible = True
  Set wdDoc = .Documents.Open(filename:="C:\MemphisCAC\Custom Office Templates\Installation Agreement.dotx", _
    AddToRecentFiles:=False, ReadOnly:=True)
  With wdDoc
    xlSht.Range("A1:G91").Copy
    .Range.Characters.Last.Paste
    .SaveAs filename:="C:\MidSouth\PENDING\" & xlSht.Range("A92").Text & ".docx", FileFormat:=wdFormatDocumentDefault, AddToRecentFiles:=False
    .Close False
With .Tables(.Tables.Count)
      .Cell(85, 1).Range.Editors.Add wdEditorEveryone
      .Cell(85, 7).Range.Editors.Add wdEditorEveryone
    End With
    .Protect Password:="", Type:=wdAllowOnlyReading
  .Quit
End With
Set wdDoc = Nothing: Set wdApp = Nothing: Set xlSht = Nothing
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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