Macro conversion help needed (2013 to 365)

JamesJud

New Member
Joined
Jul 15, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi i have an macro that saves a pdf and then emails out statements. But on conversion from 2013 to 365 it no longer works.
Could anyone have a look over the code and see if they can see what the issue is i.e. whats changed between versions that i need to update?
Any help appreciated.

VBA Code:
Sub EMAILPDF()

  Dim olApp As Object
 
  Path = "S:\Sovini Corporate\Finance\Private\Treasury Services\Accounts Receivable\Emailed Statements\"
  Number = ActiveSheet.Range("A2")
  Customer = ActiveSheet.Range("C21")
  strDate = Format(Date, "ddmmyy")
  If i > 1 Then PDF_File = Left(PDF_File, i - 1)
  PDF_File = Path & Number & " " & Customer & " " & strDate & ".pdf"
 
  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 = "Debtor Statement"
    .SentonBehalfofName = ActiveSheet.Range("F16").Text
    .To = ActiveSheet.Range("C2").Text
    .Body = "Hi," & vbLf & vbLf _
          & "Please find attached your latest statement.  If you require copy invoices, please request them now and we will send over the copies prior to them falling due for payment." & vbLf & vbLf
    .Attachments.Add PDF_File
    .Save
    .Display
  
  End With
 
  Set olApp = Nothing
 
End Sub
 
Last edited by a moderator:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Welcome to the Board!

It should still work in 365. I suspect that the issue is that it requires certain VBA libraries to be selected, and you probably have not done that in the new version yet.

The easiest way to see this is to open up the file on system/computer where it does still work, go into the VB Editor, and from the Tools menu, select References and note all the libraries that are selected.

Then, go to the system/computer where it does NOT work, and repeat the same process. You will probably notice that there are certain references that aren't selected. Find the closest match and select (usually the names are the same, but the version numbers maybe a little different).
 
Upvote 0
Thank you! Sure i will learn a lot in here :)

Just looked as you highlighed and there is one stated as MISSING on the new document.
The LsAg library relates to an old addin from our 2013 Excel - not used in the macro, but when i untick this it seems to work fine.
Does that sound right to you?
1626361880132.png

Thanks again
 
Upvote 0
Yes. If it is not being used, than it should be safe to uncheck it.
If it works, that is all that really matters!
 
Upvote 0
Always cautious to untick incase i knacker it up! But agreed, it works so lets run with that. Thanks!!
 
Upvote 0
Always cautious to untick incase i knacker it up! But agreed, it works so lets run with that. Thanks!!
If it says "MISSING", it is usually safe to uncheck it.
If it is a library that the workbook does indeed need, then you would need to find it in the list and select (sometimes may require the installation of an add-in first).
 
Upvote 0

Forum statistics

Threads
1,215,993
Messages
6,128,175
Members
449,429
Latest member
ianharper68

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