Using the code below the script loops through an Excel file and copys a ref number and pastes it to a cell further along the row (I'm just testing at the minute). Once its finished I try to open the spreadsheet but i get error 'File is already open exclusively by me do i want open it as read only'. Then if i try to run the code again another error appears saying i cant save the file do i want to save a copy? I check the Task Manager processes and Excel.exe is still open. So im thinking perhaps i need another line of code that closes the spreadsheet, am i right?
'========================================================
Sub Main()
Dim xlApp As Object
Dim xlWB As Object
Dim xlFile As String
Dim CurrCell As string
Dim CurrRow As integer
Dim iTotal as string
iTotal = 0
xlFile = "C:\Test.xls"
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open(xlFile)
For CurrRow = 2 To xlWB.Sheets(1).UsedRange.Rows.Count
CurrCell = xlWB.Sheets(1).Cells(CurrRow, 1)
xlWB.Sheets(1).Cells(CurrRow, 14) = CurrCell
iTotal + CurrCell
next
displayalerts = false
xlWB.save
End Sub
'========================================================
"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
'========================================================
Sub Main()
Dim xlApp As Object
Dim xlWB As Object
Dim xlFile As String
Dim CurrCell As string
Dim CurrRow As integer
Dim iTotal as string
iTotal = 0
xlFile = "C:\Test.xls"
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open(xlFile)
For CurrRow = 2 To xlWB.Sheets(1).UsedRange.Rows.Count
CurrCell = xlWB.Sheets(1).Cells(CurrRow, 1)
xlWB.Sheets(1).Cells(CurrRow, 14) = CurrCell
iTotal + CurrCell
next
displayalerts = false
xlWB.save
End Sub
'========================================================
"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks