Thanks for the response Peter.
The first post might not have been very clear.
We have a pre-existing spreadsheet. We are trying to *read* the formula
from a cell using Range.Formula property. On certain cells when accessing
that property Range.Formula, we get the error "1004 Application-defined or
object-defined error". In the Excel GUI you can see that the formula is
long but technically within the 1024 byte limit. There is something related
to the formula being too long or almost too long (in this case it is only
1017 bytes...).
The problem is that Range.Formula allows one to set a formula to a cell that
later on if you try to read the Range.Formula property you can't get the
formula out.
So we are looking for a way to read the Range.Formula property without
throwing an exception.
The main purpose of the code example was to show that there are cases that
one can *set* a formula successfully using Range.Formula property that then
if one tries to use Range.Formula to *get* the property it will raise the
errror.
One would expect that the Range.Formula *set* to also fail if the formula
were too long, which indeed happens in your test case below Peter. We are
wondering why you might have a formula where rg.Formula = s works but
Debug.Print rg.Formula fails, and our first code example provides that case.
The question is: is there some way to *READ* the Range.Formula for any
arbitrary cell without running into a situation where the read will raise
and exception? You can see the formula in the GUI but programmitically you
cant get to it.
""Peter Huang"" wrote in message
...
Hi Frank,
Based on my test below, I think it is caused by the limitation of formula
property.
Sub test()
Dim s As String
Dim i As Integer
s = "=11111"
For i = 1 To 448
s = s + "+" + CStr(1)
Next
Debug.Print Len(s)
Dim rg As Range
Set rg = Cells(1, 1)
rg.Formula = s
Debug.Print rg.Formula
End Sub
If we change the s = "=11111" to s = "=111111"
the error " 1004 Application-defined or object-defined error" will occur
in
the line below.
rg.Formula = s
You may have a try and let me know the result.
Also why you need such a long string formular?
Do you have any concern, maybe we can do that in another way?
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.