Help with conversion of code to Late Binding

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello All,

I've been doing research online and be hearing about early binding vs late binding. I'm currently working on a log that will be used by multiple people who i won't be able to set references too and who will probably be using different versions of excel. I feel that late binding might be the solution, unless someone know something better because i'm more use to early binding as it would appears. Anyways i have the following code and wanted to see if anyone could help me convert it to late binding. Hopefully i could then use this as a starting point to figuring how to use Late Binding for the rest of my project.

VBA Code:
Sub PerfCashMemoTP(rw As Long)

Application.EnableEvents = False

Dim TPws As Worksheet, CONws As Worksheet, SECws As Workbook, Datws As Worksheet
Dim Wordapp As Word.Application
Dim Location As Variant
Dim lrow As Long
Dim TPdate As Long, Tech As String, TechR As Long, Cash As Long


Set TPws = ThisWorkbook.Worksheets("Tract Parcels")
Set CONws = ThisWorkbook.Worksheets("Contact")
Set SECws = ThisWorkbook.Worksheets("Security")
Set Datws = ThisWorkbook.Worksheets("DATA")
Set Wordapp = CreateObject("Word.Application")

Dim wFile As String
wFile = ActiveWorkbook.Path & "\Release Letters\Perf CASH RELEASE MEMO"
If Dir(wFile) <> "" Then
    Wordapp.Documents.Open (wFile)
    Wordapp.Visible = True
Else
    MsgBox "File does not exists"
    GoTo Finaled:
End If
    
Wordapp.ActiveDocument.FormFields("TXDate").Result = Format(Now(), "mmmm dd, yyyy")

Select Case TPws.Cells(rw, "G")
    Case Is < 10000
        Select Case TPws.Cells(rw, "H")
            Case Empty, "", "N/A"
                Wordapp.ActiveDocument.FormFields("TXProject").Result = "Tract " & TPws.Cells(rw, "G").Value & " " & TPws.Cells(rw, "H").Value & " " & TPws.Cells(rw, "I").Value
            Case Else
                Wordapp.ActiveDocument.FormFields("TXProject").Result = "Tract " & TPws.Cells(rw, "G").Value
        End Select
    Case Else
        Select Case TPws.Cells(rw, "H")
            Case Empty, "", "N/A"
                Wordapp.ActiveDocument.FormFields("TXProject").Result = "Parcel Map " & TPws.Cells(rw, "G").Value & " " & TPws.Cells(rw, "H").Value & " " & TPws.Cells(rw, "I").Value
            Case Else
                Wordapp.ActiveDocument.FormFields("TXProject").Result = "Parcel Map " & TPws.Cells(rw, "G").Value
        End Select
End Select

Select Case TPws.Cells(rw, "D")
    Case "IMP AGR"
        Wordapp.ActiveDocument.FormFields("TXNum").Result = "Improvement Agreement # " & TPws.Cells(rw, "E").Value
        Wordapp.ActiveDocument.FormFields("TXNum1").Result = "Improvement Agreement # " & TPws.Cells(rw, "E").Value
    Case "PVT AGR"
        Wordapp.ActiveDocument.FormFields("TXNum").Result = "Private Improvement Agreement # " & TPws.Cells(rw, "E").Value
        Wordapp.ActiveDocument.FormFields("TXNum1").Result = "Private Improvement Agreement # " & TPws.Cells(rw, "E").Value
End Select

Wordapp.ActiveDocument.FormFields("TXDeveloper").Result = TPws.Cells(rw, "AV").Value
Wordapp.ActiveDocument.FormFields("TXDeveloper1").Result = TPws.Cells(rw, "AV").Value
Wordapp.ActiveDocument.FormFields("TXDeveloper2").Result = TPws.Cells(rw, "AV").Value

Wordapp.ActiveDocument.FormFields("TXOrgAmount").Result = Format(TPws.Cells(rw, "P").Value, "Currency")
Wordapp.ActiveDocument.FormFields("TXOrgAmount1").Result = Format(TPws.Cells(rw, "P").Value, "Currency")

Wordapp.ActiveDocument.FormFields("TXDeveloper").Result = Format(TPws.Cells(rw, "AY").Value, "mmmm dd, yyyy")

Wordapp.ActiveDocument.FormFields("TXReceiptNum").Result = TPws.Cells(rw, "AZ").Value

Wordapp.ActiveDocument.FormFields("TXNOCDate").Result = Format(TPws.Cells(rw, "AB").Value, "mmmm dd, yyyy")

Cash = TPws.Cells(rw, "S").Value
Wordapp.ActiveDocument.FormFields("TXAmountReturned").Result = Format(TPws.Cells(rw, "P").Value - Cash, "Currency")
Wordapp.ActiveDocument.FormFields("TXAmountReturned1").Result = Format(TPws.Cells(rw, "P").Value - Cash, "Currency")

COntactPerf = TPContFD(rw)
Wordapp.ActiveDocument.FormFields("TXAddress").Result = CONws.Cells(COntactPerf, "G").Value ' Addresss
Wordapp.ActiveDocument.FormFields("TXCSZ").Result = CONws.Cells(COntactPerf, "H").Value & ", " & CONws.Cells(COntactPerf, "I").Value & " " & CONws.Cells(COntactPerf, "J").Value 'City, State, Zip Entry

Wordapp.ActiveDocument.FormFields("TXBondLOC").Result = TPws.Cells(rw, "M").Value

Wordapp.ActiveDocument.FormFields("TXLMAmount").Result = Format(TPws.Cells(rw, "S").Value, "Currency")

Wordapp.ActiveDocument.FormFields("TXTech").Result = TPws.Cells(rw, "B").Value

MsgBox ("Please review Performance Memo before release.")

Finaled:

Application.EnableEvents = True

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Change this:

Code:
Dim Wordapp As Word.Application

to this:

Code:
Dim Wordapp As Object
 
Upvote 0
Is that the only changes that is needed. I'm just curious because i'm new to late binding. Do you happen to know of a good guide as to how to write in late binding format.
 
Upvote 0
Strictly speaking, that is all that late binding consists of - declaring your variables as a generic Object type rather than the specific objects from the library you were referencing with early binding. You then need to use CreateObject to instantiate your top level object (which you already were), and you need to declare any used constants (Enums) from the library - but you aren't using any here. I wrote a short article on it here if it helps.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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