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.
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
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