I opened the older app in VS 2010 and made changes based on the recommendations in the error statements that popped up. However one part that is still not working is shown below.
The error that comes back is
"file is already opened exclusively by another user or you need permission to view it"
I am opening up an access database and " select" and put it in an excel worksheet. The name of the worksheet changes every time the app is used. This worked in 2003 but not in 2010. I have goggled this and none of the answers have worked.
Dim AccessConn8 As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\UpdateExportFile\ExportFile.mdb")
AccessConn8.Open()
Dim AccessCommand8 As New System.Data.OleDb.OleDbCommand("SELECT * INTO [Excel " & _
"5.0;DATABASE=c:\" & strfilename & ".xls;HDR=YES;].[sheet1] from ExcelExport", AccessConn8) '
Try
AccessCommand8.ExecuteNonQuery()
Catch exe As DataException
Catch exc As System.Exception
MsgBox("EXCEL not updated. Contact your System Administrator. " & strfilename)
MsgBox(" ----> " & exc.Message)
AccessConn8.Close() ' added sat 2/23/15
Exit Sub
End Try
AccessConn8.Close()
Dim obook As Microsoft.Office.Interop.Excel.Workbook
Dim oexcel As Microsoft.Office.Interop.Excel.Application
oexcel = CType(CreateObject("Microsoft.Office.Interop.Excel.Application"), Microsoft.Office.Interop.Excel.Application)
obook = oexcel.Workbooks.Open("c:\" & strFileName & ".xls")
Try
With oexcel
.Visible = False
.Range("C1").Value = "'Store #"
.Range("D1").Value = "'Vendor #"
End With
Catch ex As Exception
MsgBox("error:" & ex.ToString, MsgBoxStyle.Critical, "ERROR")
End Try
' added
Dim myrange As Excel.Range
myrange = oexcel.Range("a1:l90")
myrange.Sort(Key1:=myrange.Range("c1"), Order1:=Excel.XlSortOrder.xlAscending, Header:=Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes, Orientation:=Excel.XlSortOrientation.xlSortColumns)
obook.Save()
obook.Close()
oexcel.Quit()
Can you help me downed the right path to an answer?