unable to delete folder created by macro

orsm6

Active Member
Joined
Oct 3, 2012
Messages
357
Office Version
  1. 365
Platform
  1. Windows
Hi all - this code seems to work well for anyone that uses it, however the folder that is created in the path when someone other than myself creates it cannot be deleted.

If i run the code i can delete the created folder and any contents.
My boss tested it and I was able to delete the pdf it made in the folder, i was able to technically delete the folder, but it doesn't disappear from the path.... i can open the 'supposedly' delete folder, but it has no properties and when i try to delete it again it says it doesn't exist. The boss can't even delete it.

Code:
Dim myFile As Variant
On Error GoTo errHandler

Set wbA = ActiveWorkbook
Set wsA = ActiveSheet

    strName = Worksheets("PCR Form").Cells(1, 12).value
   
'check if the PCR folder exists, if it doesn't make one
    savepath = "\\mdzausutwfnp001\Shardata\Change Management\Plant Change Requests\PCRs\"
    savepath = savepath & strName & "\"
    If Dir(savepath, vbDirectory) = "" Then
        MkDir savepath
    End If

'define where the PCRs are saved on S drive
    strPath = "\\mdzausutwfnp001\Shardata\Change Management\Plant Change Requests\PCRs\"
    strPath = savepath & "\"

'create default name for savng file
strFile = strName & " " & Format(Now(), "dd.mmm.yy hhmm AMPM") & ".pdf"
strPathFile = strPath & strFile

'export to PDF in current folder
    wsA.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=strPathFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
    'confirmation message with file info
    MsgBox "PDF file has been created: It is saved in Change Management\PCRs folder" _
      '& vbCrLf _
      '& strPathFile

exitHandler:
    Exit Sub
errHandler:
    MsgBox "Could not create PDF file"
    Resume exitHandler
End Sub

I went to delete the folder possibly just as he was closing the pdf (i didn't get the usual user has it open message) but reluctant to try again in case we make more dodgy folders ahah
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

orsm6

Active Member
Joined
Oct 3, 2012
Messages
357
Office Version
  1. 365
Platform
  1. Windows
Hi all - this macro actually works, i think there was a coincidence where i tried to delete the folder and another person was closing it at the exact same time and an issue occurred. no further support needed.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,850
Messages
5,598,457
Members
414,239
Latest member
xnanx

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
Top