HI Web application Hosted on IIS Server and when i am trying to open the excel file from vb .net code getting
Microsoft Excel cannot access the file 'E:\inetpub\Sites\iHomeSite\main\Macros\SegmentExport2_d0ad8d.xlsx'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook.
Getting error on line
Dim xlWorkBook As Excel.Workbook = xlApp.Workbooks.Open(MacroFolderPath + sTmpExcelFiles)
Please find the below code snippet.Issue need to get resolve asap.
#Region "START: Appling Macro"
Dim fi As System.IO.FileInfo
Dim MacroFolderPath As String = HttpContext.Current.Server.MapPath("\main\Macros\")
Dim MacroTemplateFolderPath As String = ConfigurationManager.AppSettings("MacroTemplateFolderPath")
' Dim MacroTemplatefilepath As String = ConfigurationManager.AppSettings("MacroTemplateFilePath")
Dim NewProductTypesDate As Date = CDateSpecial(ConfigurationManager.AppSettings("NewProductTypesDate"))
Dim MacroTemplatefilepath As String = Nothing
Dim dCreated As Date = CDateSpecial(Session("dCreated").ToString())
If (dCreated >= NewProductTypesDate) Then
MacroTemplatefilepath = ConfigurationManager.AppSettings("MacroTemplateFilePath")
Else
MacroTemplatefilepath = ConfigurationManager.AppSettings("MacroTemplateFilePathForOld")
End If
Dim sTmpExcelFiles As String = String.Empty
sTmpExcelFiles = Path.GetFileName(rr.ReportName) & "_" & Left(System.Guid.NewGuid().ToString(), 6) & "New" & "." & rr.ExportTypeExtension.Replace(".", "")
System.IO.File.Copy(sTmpExcelFullFilePath + sTmpExcelFile, MacroFolderPath + sTmpExcelFiles)
Dim TempMacroTemplatefilepath As String = MacroTemplateFolderPath & "ePSR Excel Task Template" & "_" & Left(System.Guid.NewGuid().ToString(), 6) & ".xltm"
System.IO.File.Copy(MacroTemplatefilepath, TempMacroTemplatefilepath)
Dim AppliedMacroTemplateFile As String = "ePSR Excel Task Template" & "_" & Left(System.Guid.NewGuid().ToString(), 6) & ".xltm"
Dim AppliedMacroTemplateFilepath As String = MacroFolderPath + AppliedMacroTemplateFile
Dim xlApp As New Excel.Application()
Dim xlWorkBook As Excel.Workbook = xlApp.Workbooks.Open(MacroFolderPath + sTmpExcelFiles)
Dim xlWorkSheet As Excel.Worksheet = Nothing
xlWorkBook = xlApp.Workbooks.Open(TempMacroTemplatefilepath)
xlApp.Run("Auto_open")
xlWorkBook.SaveAs(AppliedMacroTemplateFilepath, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLTemplateMacroEnabled)
xlWorkBook.Application.Quit()
xlApp.Quit()
fi = New System.IO.FileInfo(sTmpExcelFullFilePath + AppliedMacroTemplateFile)
If fi.Exists Then
Else
System.IO.File.Copy(MacroFolderPath + AppliedMacroTemplateFile, sTmpExcelFullFilePath + AppliedMacroTemplateFile)
End If
System.IO.File.Delete(MacroFolderPath + AppliedMacroTemplateFile)
System.IO.File.Delete(MacroFolderPath + sTmpExcelFile)
System.IO.File.Delete(TempMacroTemplatefilepath)
Utilities.PushFileServerDocToBrowser(sTmpExcelFullFilePath & AppliedMacroTemplateFile, AppliedMacroTemplateFile)
```#End Region