|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBA- Open a file and manipluate cell
Hi people,
i am writing a simple macro in excel but i don't know what i am doin wrong. here is the thing i wanted to do, open a file (temp.xls) and manipluate some cell data. i created a button in a file and inputed following code Private Sub CBopen_Click() Workbooks.Open Filename:="C:\temp.xls" Workbooks("temp.xls").Activate Worksheets("sheet1").Activate Range("E10").Select ActiveCell.FormulaR1C1 = "=RC[-3]-5" Range("F10").Select ActiveCell.FormulaR1C1 = "=RC[-3]*100" Range("E10:F10").Select End Sub but it gives error saying "select method of Range class failed" ( its giving error at "Range("E10").Select "). i think i am not able to point excel to right workbook. thanks in advance for the help. |
|
#2
|
||||
|
||||
|
I'm not sure why the range select method doesn't work (for some reason it's not activating the new spreedsheet).
this does work (takes a bit longer 2 code, but it's faster 2 run as well) Code:
Workbooks.Open Filename:="C:\temp.xls"
Workbooks("temp.xls").Worksheets("sheet1").Range("E10").FormulaR1C1 = "=RC[-3]-5"
Workbooks("temp.xls").Worksheets("sheet1").Range("F10").FormulaR1C1 = "=RC[-3]*100"
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > VBA- Open a file and manipluate cell |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|