-
I am trying to open an existing spreadsheet and add a few extra lines then close the spreadsheet.
Private Sub Command3_Click()
Dim spreadsheetname As String
Dim objXLS As New Excel.Application
spreadsheetname = "c:\vbstuff\book3.xls"
With objXLS
.Workbooks.Open spreadsheetname
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Range("F1").Select
ActiveCell.FormulaR1C1 = "xxx"
Range("F2").Select
ActiveCell.FormulaR1C1 = "xxx"
Range("F3").Select
ActiveCell.FormulaR1C1 = "xxx"
Range("F4").Select
ActiveCell.FormulaR1C1 = "xxx"
Range("F7").Select
End With
Set objXLS = Nothing
MsgBox "finito"
End Sub
I want to look and see if it has done as I asked. But when I open the excel ss I get this message.
"book3.xls is already open , reopening it will discard any changes do you want to reopen "
I dont think I am releasing the spreadsheet again in my code , how do I do this ? . I want the code to run, add the extra data to the ss then when the code is finnished I wish to then open excel , open my workbook and see the changes without any hassle
cheers
-
I see you called workbook.Open.
Is there a similar command to close the workbook...say:
workbook.close
or something to that nature. That seems to be the only problem with the code you have posted.
hope it helps.
-
You need to save it then quit.
.saveas "path\filename"
.application.quit
-
thanks
thanks dude , that was it , it always helps to have another pair of fresh eyes looking at your code.
thanks