PDA

View Full Version : [SOLVED:] Help with error



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

Jacob Hilderbrand
04-27-2005, 07:35 PM
You can just check the cell.



If Cells(Row, Col).Value = "" Then
'Do This
Else
'Do That
End If

Erays
04-28-2005, 03:30 PM
Thank you, You have done it again I appreciate your help.





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).Value = "" Then
GoTo no1
Else
Word.Insert Cells(5, 3).Value
Word.InsertPara
GoTo no1
End If
no1:
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
If Cells(26, 3).Value = "" Then
GoTo no2
Else
Word.Insert Cells(26, 3).Value
Word.InsertPara
GoTo no2
End If
no2:
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




I have uploaded a version that works.!

Jacob Hilderbrand
04-28-2005, 03:37 PM
You're Welcome :beerchug:

Take Care