0

I'm currently trying to get my VB.net program to "SaveAs" a Excel Workbook, only to get Exception HRESULT : 0x800A03EC on the actual SaveAs line.

I checked my Filepath and it's fine and working, so I'm clueless at the moment

Here is my code where I declare Excel-related objects

Dim ExcelApp As New Interop.Excel.Application()
Dim Classeur = ExcelApp.Workbooks.Open("C:\Program Files (x86)\Software_name\template.xlsx")
Dim Feuille = Classeur.Sheets("sheet_name")

Then I declare values that I get from textboxes

Dim FileName As String = Textbox1.text + Textbox2.text +  Textbox3.text

Dim FilePath As String = "\\192.168.1.xxx\some\folders\where\names\never\change\" & Date.Today.Year & "\" & FileName & "\"

MkDir(FilePath)

Dim StrPath As String = FilePath & FileName & ".xlsx" 'So I create a document named after FileName

And then I save with

'This works
Classeur.ActiveSheet.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, FilePath & FileName & ".pdf")

'This doesn't works
Classeur.SaveAs(StrPath)
Thryn
  • 355
  • 1
  • 11

1 Answers1

0

I ended up finding the issue : The name used to save the file CANNOT end with a space (" ") and it appears that my users were doing it without really noticing. So I just added this snippet of code and it works like a charm.

Dim NameLength As Integer
Dim NameText As String

NameText = TextBox.Text
If Strings.Right(NameText, 1) = " " Then
   NameLength = NameText.Length - 1
   NameText = Strings.Left(NameText, NameLength)
End If
Thryn
  • 355
  • 1
  • 11