DeannaF829
Technical User
I'm trying to update an excel spreadsheet with the following code:
Private Sub ExportToFile(objRecord As Recordset, Optional Delimiter As String = ",")
Const xlCSV = 6
Dim EXPORT_FILE_PATH1 As String
Dim objExcel
Dim objWorkbook
Dim objWorksheet
EXPORT_FILE_PATH1 = "C:\Daily_Data.csv"
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Documents and Settings\Deanna\My Documents\Daily_Data.xls")
objExcel.DisplayAlerts = False
objExcel.Visible = True
Set objWorksheet = objWorkbook.Worksheets("Sheet1")
objWorksheet.SaveAs EXPORT_FILE_PATH1, xlCSV
Set objWorkbook = objExcel.Workbooks.Close("C:\Documents and Settings\Deanna\My Documents\Daily_Data.xls")
objExcel.quit
End Sub
As soon as it gets to the line that says "Set objWorkbook = objExcel.Workbooks.Open", I get an error Cannot access 'Daily_Data.xls'
Here's the tricky part: This code works fine on one computer, but not on another (same version of VB, Excel, Windows, etc...)
Private Sub ExportToFile(objRecord As Recordset, Optional Delimiter As String = ",")
Const xlCSV = 6
Dim EXPORT_FILE_PATH1 As String
Dim objExcel
Dim objWorkbook
Dim objWorksheet
EXPORT_FILE_PATH1 = "C:\Daily_Data.csv"
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Documents and Settings\Deanna\My Documents\Daily_Data.xls")
objExcel.DisplayAlerts = False
objExcel.Visible = True
Set objWorksheet = objWorkbook.Worksheets("Sheet1")
objWorksheet.SaveAs EXPORT_FILE_PATH1, xlCSV
Set objWorkbook = objExcel.Workbooks.Close("C:\Documents and Settings\Deanna\My Documents\Daily_Data.xls")
objExcel.quit
End Sub
As soon as it gets to the line that says "Set objWorkbook = objExcel.Workbooks.Open", I get an error Cannot access 'Daily_Data.xls'
Here's the tricky part: This code works fine on one computer, but not on another (same version of VB, Excel, Windows, etc...)