Reputation: 184
I've googled everything. Still no idea what's happening.
I have a vb.net form that let's me insert txt file values into excel.
The thing is it gives me an error when i use
xlWorkSheet.SaveAs("C:\" & TextBox3.Text & ".xlsx")
but when i use xlWorkSheet.SaveAs("C:\Users\User\Desktop\" & TextBox3.Text & ".xlsx")
it works fine ( in my computer ). In other computers it gives me the same error..
The error is System.Runtime.InteropServices.COMException , and the "extension" depends almost everytime. Microsoft Excel can't access the file 'C:\C6703D00'. ( i refer to C6703D00 nowhere)
[kinda translating]- Error details:
• Filename or path don't exist
• the file is already in use.
• the workbook you're trying to save has the same name as an open book.
I'm using Visual Studio 2013 vb.net .netframework v4.5 .. i can post more code in question if you need.
Upvotes: 1
Views: 2871
Reputation: 5157
When code works on your computer and not another computer at the point of the SaveAs then you should validate that the path exists e.g. where .... is a TODO for your path
If Not String.IsNullOrWhiteSpace(TextBox3.Text) Then
Dim fileName As String = IO.Path.Combine("C:\....", TextBox3.Text)
Dim folder As String = IO.Path.GetDirectoryName(fileName)
If IO.Directory.Exists(folder) Then
' save
Else
' path not found
End If
End If
Other issues could not the user does not have access to the folder.
Upvotes: 1