Erays
04-27-2005, 07:14 PM
I have created an excel workbook that creates a word document out of data entered on the worksheet however if there is no data in one of the cells it will create an error, what I want to do is use if and elseif or use error handling. the second address line will sometimes have no data in it and I would want the macro to handle and go ahead and write the address.
Sub AmyLetter()
Dim Word As Object
Dim Workbook
'-- Begin the Word setup
Application.ScreenUpdating = False
Set Word = CreateObject("Word.Basic")
Word.FileNewDefault
Word.AppShow
Word.FormatFont Font:="Courier New", Points:=12
Word.Bold 1
Word.FormatParagraph Alignment:=0
Word.Insert Cells(3, 3).Value
Word.InsertPara
Word.Insert Cells(4, 3).Value
Word.InsertPara
If Cells(5, 3) = True Then
On Error GoTo no1
no1:
ElseIf Cells(5, 3) = False Then
Word.Insert Cells(5, 3).Value
Word.InsertPara
End If
Word.Insert Cells(6, 3).Value & ", " & Cells(7, 3).Value & " " & Cells(8, 3).Value
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.Insert Cells(10, 3).Value
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.Insert Cells(24, 3).Value
Word.InsertPara
Word.Insert Cells(25, 3).Value
Word.InsertPara
Word.Insert Cells(26, 3).Value
Word.InsertPara
Word.Insert Cells(27, 3).Value & ", " & Cells(28, 3).Value & " " & Cells(29, 3).Value
Word.FormatFont Font:="Courier New", Points:=10
Word.Bold 0
Word.FormatParagraph Alignment:=0
Application.ScreenUpdating = True
End Sub
Sub AmyLetter()
Dim Word As Object
Dim Workbook
'-- Begin the Word setup
Application.ScreenUpdating = False
Set Word = CreateObject("Word.Basic")
Word.FileNewDefault
Word.AppShow
Word.FormatFont Font:="Courier New", Points:=12
Word.Bold 1
Word.FormatParagraph Alignment:=0
Word.Insert Cells(3, 3).Value
Word.InsertPara
Word.Insert Cells(4, 3).Value
Word.InsertPara
If Cells(5, 3) = True Then
On Error GoTo no1
no1:
ElseIf Cells(5, 3) = False Then
Word.Insert Cells(5, 3).Value
Word.InsertPara
End If
Word.Insert Cells(6, 3).Value & ", " & Cells(7, 3).Value & " " & Cells(8, 3).Value
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.Insert Cells(10, 3).Value
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.InsertPara
Word.Insert Cells(24, 3).Value
Word.InsertPara
Word.Insert Cells(25, 3).Value
Word.InsertPara
Word.Insert Cells(26, 3).Value
Word.InsertPara
Word.Insert Cells(27, 3).Value & ", " & Cells(28, 3).Value & " " & Cells(29, 3).Value
Word.FormatFont Font:="Courier New", Points:=10
Word.Bold 0
Word.FormatParagraph Alignment:=0
Application.ScreenUpdating = True
End Sub