I can not duplicate that error.
Why would you run it? You should always Compile code before running it. I guess you put the code in a Module.
When you compile, you can see the reference error or not if you added it. You will also see that you did not define variables that you concatenated. I most always recommend Option Explicit as first line of code. You can set that Option to be added automatically in VBE.
I do not recommend saving files to c:\.
After saving the file, you should close the document and Set the objects to Nothing.
Use Debug's F8 to execute your code line by line to see which line has the problem.
Option Explicit
Sub DespatchPdf()
Dim wApp As Word.Application, wDoc As Word.Document
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Open("C:\Users\graham\Dropbox\Dropbox Backed Up Files\4. Southcourt\6. Order Processing\despatch_note_template.docx")
With wDoc.Content.Find
.Text = "Date:"
.Replacement.Text = "Date: " & orderdate
.Execute Replace:=wdReplaceAll
.Text = "Customer Reference:"
.Replacement.Text = "Customer Reference: L9/" & custid
.Execute Replace:=wdReplaceAll
.Text = "Contact Telephone:"
.Replacement.Text = "Contact Telephone: " & custtel
.Execute Replace:=wdReplaceAll
.Text = "Delivery To:"
.Replacement.Text = "Delivery To: " & Chr(11) & Chr(11) & custtitle & " " & custfname & " " & custsurname & Chr(11) & custaddress1 & Chr(11) & custaddress2 & Chr(11) & custaddress3 & Chr(11) & custaddress4
.Execute Replace:=wdReplaceAll
End With
wApp.ActiveDocument.SaveAs "C:\MyDoc.pdf", 17
End Sub
Sub Test_SearchReplaceInDoc()
SearchReplaceInDoc "x:\MSWord\SearchReplace\SearchReplaceInDoc.doc", "***XX", "123", True, False
End Sub
'http://www.vbaexpress.com/forum/showthread.php?t=38958
Sub SearchReplaceInDoc(doc As String, findString As String, replaceString As String, _
Optional docVisible As Boolean = True, _
Optional closeDoc As Boolean = True)
Dim wdApp As Object, wd As Object
If Dir(doc) = "" Then Exit Sub
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then Set wdApp = CreateObject("Word.Application")
On Error GoTo 0
Set wd = wdApp.Documents.Open(doc)
wdApp.Visible = docVisible
With wd
'.FormFields("Brand").Result = Cells(rn, "B")
End With
With wd.Content.Find
.Text = findString '"***XX"
.Replacement.Text = replaceString '"123"
.Forward = True
.Wrap = 1
.Execute Replace:=2
End With
If closeDoc Then
Set wd = Nothing
Set wdApp = Nothing
End If
End Sub