0
Set Worksh = Worksheets("SampleWorksheet")
Set myRange = Worksh.Range("F1")
msgbox myRange.Value, , ""   'WORKS: current value in "F1" cell is displayed 
myRange.Value = 100            'DOESNT WORK! : value in cell DOES NOT change

I have no idea - it was supposed to work. Any ideas? Thanks

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by edek
0

Hi,
Are you saving the document?? the following code will work:

Private Sub Command1_Click()

Dim xl
Dim Worksh
Dim xlwbook
    
    Set xl = CreateObject("Excel.Application")
    Set xlwbook = xl.Workbooks.Open("C:\temp.xls")
    Set Worksh = xlwbook.Sheets.Item(1)
    
    xl.Visible = True
    
    Set myRange = Worksh.Range("F1")
    MsgBox myRange.Value, , ""
    myRange.Value = 100
    
    xl.ActiveWorkbook.save
    xl.ActiveWorkbook.Close False, "C:\temp.xls"
    xl.quit
    
End Sub
0

My code is very simmilar but is in function not in sub. May it be the problem? Maybe from functions you can't edit other cells but the one the function is returning it's value to (the one with formula "=MyFunction() ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.