Delete excel Documents from your project folder

Delete excel Documents from your project folder

ndillner343SKL
Enthusiast Enthusiast
380 Views
2 Replies
Message 1 of 3

Delete excel Documents from your project folder

ndillner343SKL
Enthusiast
Enthusiast

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) 

 

0 Likes
Accepted solutions (2)
381 Views
2 Replies
Replies (2)
Message 2 of 3

basautomationservices
Advocate
Advocate
Accepted solution

if this is iLogic:

 

If System.IO.File.Exists(myXLS_File) Then
    System.IO.File.Delete(MyXLS_File)
End if
Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 3 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

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.

EESignature


Blog: hjalte.nl - github.com