I'm looking to delete an excel document (.xlsx) from my project folder.
This is my best attempt,
'define the file to create/open myXLS_File = ThisDoc.Path & "\TempFile.xlsx" 'define Excel Application object excelApp = CreateObject("Excel.Application") 'set Excel to run visibly, change to false if you want to run it invisibly excelApp.Visible = False 'suppress prompts (such as the compatibility checker) excelApp.DisplayAlerts = False excelWorkbook = excelApp.Workbooks.Delete(myXLS_File)
Solved! Go to Solution.
Solved by JelteDeJong. Go to Solution.
Solved by basautomationservices. Go to Solution.
if this is iLogic:
If System.IO.File.Exists(myXLS_File) Then
System.IO.File.Delete(MyXLS_File)
End if
In addition on @basautomationservices reply. You can use the function IO.Path.Combine(...) This function will add \ in your path if needed. (I see that you hard coded them in your OP) Because that function will look automatically for you if \ are needed it's less likely for you to get bugs.
Another thing I like is the FileInfo class. It has all kinds functions that you might need. Your could could look like this.
[iLogic code]
Dim excelFilePath = System.IO.Path.Combine(ThisDoc.Path, "TempFile.xlsx") Dim excelFileInfo As New System.IO.FileInfo(excelFilePath) If (excelFileInfo.Exists) Then excelFileInfo.Delete()
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Can't find what you're looking for? Ask the community or share your knowledge.