Share via

excel vba command kill fails

Anonymous
2024-02-14T17:39:45+00:00

Windows 10 office 365 home

why does "Kill" fail when file is on onedrive?

Sub killit()

'Kill with path to onedrive fails "File not found"
' lcFullPath = Application.ActiveWorkbook.Path & "/Diddly Results.pdf"

'Kill with path to local drive deletes file. Removal syncs to onedrive
lcFullPath = "c:/users/owner/onedrive/diddly_share/Diddly Results.pdf"

    'FileSystem.Kill lcFullPath  
    Kill lcFullPath  

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2024-02-16T11:53:16+00:00

    Thank you for the information.

    My question arose because of an issue with the coding below:

    'Generate a PDF copy for attachmnt to the email
    Sheets("Rslt Sheet").Range("RsltSheetVet").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    lcPath & "Diddly Results Vets.pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
    OpenAfterPublish:=False
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
    .To = "Starters"
    '.To = "D Alan Jones <@yahoo.co.uk>; Huw Knight <@ntlworld.com>; Ian Orr <@gmail.com>; Jeremy Sherrard-Smith <@gmail.com>; Mark Ryan <@gmail.com>; Matt Hollis (matthew_@btinternet.com); Michael & Eleanor <@gmail.com>; Ray Anderson <@btopenworld.com>"
    .CC = ""
    .BCC = ""
    .Subject = Range("RsltHeaderVet").Value '"Diddly Results Sheet" & Date
    .Body = lcFundMsg
    .Attachments.Add lcPath & "Diddly Results Vets.pdf" 'Dest.FullName
    ' You can add other files by uncommenting the following statement.
    '.Attachments.Add ("C:\test.txt")
    ' In place of the following statement, you can use ".Display" to
    ' display the e-mail message.
    .display
    '.Send
    End With 'OutMail

    The pdf file created remains in the specified folder. When using the code to send the next email the old pdf is sometimes attached to the new email (it sees to be a timing issue with sync). My thought was to delete the old pdf file before creating the new one. As the project is shared with others users via onedrive the inability to delete is a problem. I looked at using the filesystemobject deletefile method but investigation with debug seems to indicate that fso also only sees local drives.

    If you can suggest a way round this issue it will be appreciated

    Was this answer helpful?

    0 comments No comments
  2. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2024-02-14T18:25:51+00:00

    This kind of VBA functions works on your local PC only, you can not access files on http sides (OneDrive nor Sharepoint Online).

    Andreas.

    Was this answer helpful?

    0 comments No comments