VBA stops working when I move file

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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I am such an idiot.

I worked it out. It only took me three weeks!!

I was actually moving the file to a different computer, via TeamViewer and, of course, the other computer has a different name, so the Path is incorrect.

Path = "C:\Users\EPC\Dropbox\Payment Applications"

"EPC" is the name of the computer it works on. "HUY" is the name of the other computer

I am such a lemon.
 
Last edited:
Upvote 0
Shortened it a little

Code:
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.Interior.ColorIndex = xlNone
Range("A1").AutoFilter Field:=1, Criteria1:="<>"
    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
Rows("2:4").EntireRow.Hidden = True
Range("C21").Activate
    With Range("C16:E16,C19,E19,C21,A23:E160,E165").Interior
        .ColorIndex = 40
        .Pattern = xlSolid
    End With
End With
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
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top