superkopite
Board Regular
- Joined
- Jun 28, 2007
- Messages
- 54
Hi Guys and Gals,
I have a file with some VBA that work brilliantly for me. However, I need to move the location of it, currently sitting on the desktop, b ut when I move it, I get an error in the VBA.
Sub PDFTOEMAIL()
Dim olApp As Object
Sheet1.Unprotect Password:=""
Path = "C:\Users\EPC\Dropbox\Payment Applications" ' pls adjust
Salesman = ActiveSheet.Name
If i > 1 Then PDF_File = Left(PDF_File, i - 1)
PDF_File = Path & Salesman & ".pdf"
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select
Selection.AutoFilter Field:=1, Criteria1:="<>"
ActiveWindow.SmallScroll Down:=-9
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_File, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
With olApp.CreateItem(0)
.Subject = "Payment Application"
.To = Range("G17").Value
.Body = "Hi " & Range("m16").Value & vbLf & vbLf _
& "Please find attached Payment Application." & vbLf & vbLf _
& "Kind Regards," & vbLf & vbLf _
& "James"
.Attachments.Add PDF_File
.Save
.Display
End With
Selection.AutoFilter Field:=1
Rows("2:4").Select
Selection.EntireRow.Hidden = True
Range("C16:E16,C19,E19,C21").Select
Range("C21").Activate
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
Range("A23:E160").Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
ActiveWindow.SmallScroll Down:=141
Range("E165").Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
ActiveWindow.SmallScroll Down:=-174
Range("C10").Select
Sheet1.Protect Password:=""
' if you want to delete it
'Kill PDF_File
Set olApp = Nothing
End Sub
This is where it errors out;
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_File, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
Does anyone have any ideas as to why?
Mucho Thankso
James
I have a file with some VBA that work brilliantly for me. However, I need to move the location of it, currently sitting on the desktop, b ut when I move it, I get an error in the VBA.
Sub PDFTOEMAIL()
Dim olApp As Object
Sheet1.Unprotect Password:=""
Path = "C:\Users\EPC\Dropbox\Payment Applications" ' pls adjust
Salesman = ActiveSheet.Name
If i > 1 Then PDF_File = Left(PDF_File, i - 1)
PDF_File = Path & Salesman & ".pdf"
Cells.Select
Selection.Interior.ColorIndex = xlNone
Range("A1").Select
Selection.AutoFilter Field:=1, Criteria1:="<>"
ActiveWindow.SmallScroll Down:=-9
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_File, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
With olApp.CreateItem(0)
.Subject = "Payment Application"
.To = Range("G17").Value
.Body = "Hi " & Range("m16").Value & vbLf & vbLf _
& "Please find attached Payment Application." & vbLf & vbLf _
& "Kind Regards," & vbLf & vbLf _
& "James"
.Attachments.Add PDF_File
.Save
.Display
End With
Selection.AutoFilter Field:=1
Rows("2:4").Select
Selection.EntireRow.Hidden = True
Range("C16:E16,C19,E19,C21").Select
Range("C21").Activate
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
Range("A23:E160").Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
ActiveWindow.SmallScroll Down:=141
Range("E165").Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
ActiveWindow.SmallScroll Down:=-174
Range("C10").Select
Sheet1.Protect Password:=""
' if you want to delete it
'Kill PDF_File
Set olApp = Nothing
End Sub
This is where it errors out;
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_File, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
Does anyone have any ideas as to why?
Mucho Thankso
James