View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jimmy Jose Jimmy Jose is offline
external usenet poster
 
Posts: 2
Default How to handle "Invalid Worksheet Name" error programatically in VB

Here is the solution

Case "EXCEL"

strFullPath = strSpoolPath & strReportID & ".xls"

strOutputFormat = Constants.acFormatXLS

If InStr(strRepName, ":") Then

Dim strNewRepName As String

strNewRepName = Replace(strRepName, ":", "_")

objAcc.DoCmd.CopyObject(, strNewRepName,
AcObjectType.acReport, strRepName)


objAcc.DoCmd.OutputTo(AcOutputObjectType.acOutputR eport, strNewRepName,
Constants.acFormatXLS, strFullPath, False)

objAcc.DoCmd.DeleteObject(AcObjectType.acReport,
strNewRepName)

Else


objAcc.DoCmd.OutputTo(AcOutputObjectType.acOutputR eport, strRepName,
Constants.acFormatXLS, strFullPath, False)

End If

strFilename = strReportID & ".xls"


"Jimmy Jose" wrote:

Hi,
I am trying to open an existing excel workbook. It pops up an error
stating that
Errors were detected in 1598.xls but Microsoft Office Excel was able to
open the file by making the repairs listed below. Save the file to make these
repairs permanent. Renamed invalid sheet name.

This message is popped up when the XLS file has work sheet with the name
like rpt:coursedetails etc.,

When trying to open this workbook, programmatically in VB.Net, the following
exception is raised:

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in ExcelObjetCreation.exe

Additional information: Exception from HRESULT: 0x800A03EC.

Could you please tell me how this exception can be handled?

DO THERE IS ANY WAY

The code that i have written to open a currepted file is as below

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim xlApp As New Excel.Application
Dim xlworkBook As Workbook
Dim xlSheet As Worksheet
Dim ExcelFile_Path As String = "C:\XLReports\913.xls"
xlApp = CreateObject("Excel.Application")
xlSheet = xlApp.ActiveSheet()
MsgBox(xlSheet.Name)
xlworkBook = xlApp.Workbooks.Open(ExcelFile_Path)
MsgBox(xlworkBook.Name)
xlSheet = xlworkBook.Sheets(1)
MsgBox(xlSheet.Name)
xlSheet.Name = "Mysheet"
MsgBox(xlSheet.Name)

End Sub

I get an error at the following code
xlworkBook = xlApp.Workbooks.Open(ExcelFile_Path)


I feel like that its not possible to open a workbook which has a corrupted
sheetname.
How do microsoft open such file and ask for renaming it,and rename it?