Hi again
Got a problem where outlook comes up with an error saying "Outlook does not recognize one or more names" where on the spreadsheet it is referencing to has a single email address.
Even when i type in the email address directly into the code with the same error
Now if i swap .send with .display, the email works fine but is useless for automation purposes.
Anybody got any ideas, cause i'm stumped
Got a problem where outlook comes up with an error saying "Outlook does not recognize one or more names" where on the spreadsheet it is referencing to has a single email address.
Even when i type in the email address directly into the code with the same error
Now if i swap .send with .display, the email works fine but is useless for automation purposes.
Anybody got any ideas, cause i'm stumped
Code:
Sub format()
Application.ScreenUpdating = False
Dim fmt As Worksheet, inp As Worksheet, v0 As Worksheet
Set fmt = Worksheets("Format")
Set inp = Worksheets("import")
Set v0 = Worksheets("Parameters")
inp.Activate
''-----------------------------------------
'Find and insert Deliver to address
Range("B1:B20").Find("Deliver To", LookIn:=xlValues, MatchCase:=False).Activate
ActiveCell.Offset(0, 1).Activate
If IsEmpty(ActiveCell) = True Then
ActiveCell.Offset(1, 0).Activate
End If
Dim dt1 As Variant, dt2 As Variant, dt3 As Variant
dt1 = Application.VLookup(ActiveCell.Value, Worksheets("Parameters").Range("A:D"), 2, False)
dt2 = Application.VLookup(ActiveCell.Value, Worksheets("Parameters").Range("A:D"), 2 + 1, False)
dt3 = Application.VLookup(ActiveCell.Value, Worksheets("Parameters").Range("A:D"), 2 + 2, False)
'VLookup Error Handling
If IsError(dt1) Then
dt1 = ActiveCell.Value
dt2 = "(Address Not programmed)"
dt3 = ""
End If
With fmt
.Range("C11").Value = dt1
.Range("C12").Value = dt2
.Range("C13").Value = dt3
End With
''-----------------------------------
'Body Content Insertion
Dim rng As Range, rng2 As Range
Dim mr As Long, r1 As Long, r2 As Long
Dim rstart As Long, rend As Long
'sets maximum row scan
mr = v0.Range("K1").Value
For r1 = 1 To mr Step 1
'finds the beginning of each POs by looking for the *** START OF PURCHASE ORDER - *** part
If InStr(1, LCase(Range("C" & r1)), "start of purchase order") > 0 Then
rstart = r1
'get the last row of that section
For r2 = r1 To mr Step 1
If InStr(1, LCase(Range("C" & r2)), "end of purchase order") > 0 Then
rend = r2
Exit For
End If
Next r2
For rstart = rstart To rend Step 1
'move data over to formatting
Select Case Range("B" & rstart).Value
Case "Order Number:"
fmt.Range("F9").Value = Range("C" & rstart)
Case "Order Status:"
fmt.Range("F14").Value = Range("C" & rstart)
Case "Order Version:"
fmt.Range("F10").Value = Range("C" & rstart)
Case "Order Date:"
With fmt.Range("F11")
.Value = Range("C" & rstart)
.NumberFormat = "dd/mm/yyyy"
End With
Case "Delivery Date:"
With fmt.Range("F12")
.Value = Range("C" & rstart)
.NumberFormat = "dd/mm/yyyy"
End With
Case "Item Number"
rstart = rstart + 1
itemmove (rstart)
End Select
Next rstart
Dim pdfpath As String, pdffn As String
'Export to PDF
pdfpath = v0.Range("K7") & "\"
pdffn = "colespo.pdf"
fmt.ExportAsFixedFormat Type:=xlTypePDF, filename:=pdfpath & pdffn
'email the PDF
Dim outapp As Object
Dim outmail As Object
Set outapp = CreateObject("Outlook.Application")
Set outmail = outapp.CreateItem(0)
With outmail
.to = v0.Range("K10").Value
.Subject = v0.Range("K11").Value
.body = v0.Range("K12").Value
.Attachments.add pdfpath & pdffn
.Send
End With
Set outmail = Nothing
Set outapp = Nothing
Call clearformatting
inp.Activate
End If
Next r1
Application.ScreenUpdating = True
End Sub
Last edited: