Upgraded to M365 and getting VBA 400 error...

richierich1985

New Member
Joined
Jan 14, 2022
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Morning everyone, looking for some help.

I've written some code for an Excel form I am building at work. The form sits on a SharePoint site, essentially a user will complete the form... and then click a button to attach it to a new email in Outlook.

The code was working up until yesterday, when our IT department helpfully 'upgraded' me to M365. I know get the 400 error when clicking the button to attach it to an email.

The code saves it to a temp folder, attaches it to the email, then deletes from the temp folder. So I am sure the issue is being caused by M365. Any ideas?? Code below...

_____________________
VBA Code:
Sub Email_Sheet()


   Dim oApp As Object

   Dim oMail As Object

   Dim LWorkbook As Workbook

   Dim LFileName As String


   Application.ScreenUpdating = False

   Application.DisplayAlerts = False

 
   ActiveSheet.Copy

   Set LWorkbook = ActiveWorkbook


   LFileName = LWorkbook.Name & " Email.xlsx"

   On Error Resume Next

   Kill LFileName

   On Error GoTo 0

   LWorkbook.SaveAs fileName:=LFileName

 
   Set oApp = CreateObject("Outlook.Application")

   Set oMail = oApp.CreateItem(0)



   With oMail

      .To = XXXXXXXXXXX@XXXXX.com

      .Subject = "NST New Incident: " & Range("D15")
   
      .Body = Range("D15") & vbCrLf & vbCrLf & "Thank you for raising a Support Ticket with the Network Support Team. Please ensure you attach any relevant documentation/photos relating to this Support Ticket before pressing the send button to submit your ticket to the team." & vbCrLf & vbCrLf & "We will respond to your email within a 2 hour SLA, if however you raise a ticket on a Saturday or Sunday we will then respond to you before 11am on Monday."

   
      .Attachments.Add LWorkbook.FullName

      .Display

   
   End With

 
   LWorkbook.ChangeFileAccess Mode:=xlReadOnly

   Kill LWorkbook.FullName

   LWorkbook.Close SaveChanges:=False


   Application.ScreenUpdating = True

   Application.DisplayAlerts = True

 

   Set oMail = Nothing

   Set oApp = Nothing

 

End Sub
 
Last edited by a moderator:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Where does the error occur?
 
Upvote 0
Morning Rory,

It seems to occur when creating the temporary workbook. It should create the workbook, save it to a temp folder, add to email, then delete from temp folder.

I believe it occurs when trying to save to a temp folder.

Thank you, Richard
 
Upvote 0
Your code doesn't actually specify where to save it, so it will go into whatever the current directory is. Perhaps you need to add a path?
 
Upvote 0
So perhaps try just dropping in "C:/" into the code?

Thank you, this is the first time I've ever used VBA so it's quite a learning curve.

I think the difference with the 365 version of Excel is it auto saves to OneDrive/SharePoint rather than on your hard drive, so I think that is causing the issue. Previously it would just save it to a temp folder, but its trying to save it temporarily to OneDrive causing an issue. Fun and games eh!
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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