I have created an VB code which flech data from excel cells to ms word and save it as PDF.
But when the macro try to take the empty cells in excel it throws a run time erroe 4198.
Can some body help me on this.

Private Sub Button2_Click()
Dim StrFileName As String

Dim iloop As Long

'Dim afso As New FileSystemObject, arange As Range

Dim arrange As Range

Dim aWApp As Word.Application, aWDoc As Word.Document

Dim SigString As String

Dim objOutlook As New Outlook.Application

Dim objOutlookMsg As Outlook.MailItem

 Dim i As Long
     Range("A1").Select
     Range(Selection, Selection.End(xlDown)).Select
     flecnt = Selection.Count
For i = 3 To flecnt
    Set aWApp = New Word.Application
    aWApp.Visible = True
    aWApp.DisplayAlerts = wdAlertsNone
    aWApp.Visible = True     
    temppth = "f:\ttt.docx"
                      Set aWDoc = aWApp.Documents.Open(temppth)
                       WL = "f:\"
            wlpth = WL & "W.docx"
    Set myRange = aWDoc.Content
    tfindtext = "LLFL"
    'ordersplit = Sheets("1").Cells(i, 3)
    treplacetext = Sheets(1).Cells(i, 1)
    myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
    Set myRange1 = aWDoc.Content
    tfindtext = "ZDEL"
    'ordersplit = Sheet5.Cells(1, 3)
   treplacetext = Sheets(1).Cells(i, 2)
    myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
    Set myRange2 = aWDoc.Content
    tfindtext = "AM ORDER"
    'ordersplit = Sheet5.Cells(i, 6)
     treplacetext = Sheets(1).Cells(i, 6)
    myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
    Set myRange3 = aWDoc.Content
    tfindtext = "ST DATE"
    'ordersplit = Sheet5.Cells(i, 5)
     treplacetext = Sheets(1).Cells(i, 4)
    myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
    Set myRange4 = aWDoc.Content
    tfindtext = "ED DATE"
    'ordersplit = Sheet5.Cells(i, 2)
     treplacetext = Sheets(1).Cells(i, 5)
    myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
    Set myRange5 = aWDoc.Content
    tfindtext = "#SAID#"
    'ordersplit = Sheet5.Cells(i, 6)
     treplacetext = Sheets(1).Cells(i, 3)
    myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
     Set myRange6 = aWDoc.Content
     tfindtext = "Sm Name"
    'ordersplit = Sheet5.Cells(i, 7)
     treplacetext = Sheets(1).Cells(i, 8)
     myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
    Set myRange7 = aWDoc.Content
     tfindtext = "SH Company"
    'ordersplit = Sheet5.Cells(i, 7)
     treplacetext = Sheets(1).Cells(i, 9)
     myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
     Set myRange8 = aWDoc.Content
     tfindtext = "Address Line"
    'ordersplit = Sheet5.Cells(i, 7)
     treplacetext = Sheets(1).Cells(i, 10)
     myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
     Set myRange9 = aWDoc.Content
     tfindtext = "City"
    'ordersplit = Sheet5.Cells(i, 7)
     treplacetext = Sheets(1).Cells(i, 11)
     myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
     Set myRange10 = aWDoc.Content
     tfindtext = "Postal"
    'ordersplit = Sheet5.Cells(i, 7)
     treplacetext = Sheets(1).Cells(i, 12)
     myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
     Set myRange12 = aWDoc.Content
     tfindtext = "Countryz"
    'ordersplit = Sheet5.Cells(i, 7)
     treplacetext = Sheets(1).Cells(i, 14)
     myRange.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
   ' Set myRange10 = aWDoc.Content
   ' tfindtext = "UUUUUUUUUUUU"
    'ordersplit = Sheet5.Cells(i, 12)
   ' treplacetext = Replace(ordersplit, Chr(10), Chr(13))
    'myRange10.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
    'myRange10.Find.Execute FindText:=tfindtext, ReplaceWith:=treplacetext, Replace:=wdReplaceAll
    aWDoc.SaveAs2 "C:\USWL\" & Sheets(1).Cells(i, 2) & ".pdf", 17
    aWDoc.Close False
    aWApp.Quit False
    Set objOutlookMsg = Nothing
    Next i
End Sub

Keep in mind you posted 100 lines of code but didn't point out the line that failed.

However, if you know it fails on empty cells, add code to handle that. As this is your first post, be sure to read the sticky about making a good post at https://www.daniweb.com/programming/web-development/threads/435023/read-this-before-posting-a-question

Tell us which line number fails if you want to drill down on that line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.