D
DudMc3
The following discussion pertains to Microsoft Excel 2000.
There appears to be an undocumented limitation on the Let procedure behind
the CommandText property on the Excel.PivotCache class.
When getting the property, a String value is returned, not a Variant(String)
type as noted in the documentation. This string contains the SQL text in the
PivotCache. The string is not limited to 255 characters in length.
When setting (letting) the property, you can pass it a string of length less
than or equal to 255 characters. If you pass a longer string, VBA raises an
runtime error 1004.
There is a workaround: instead of passing a String type value, break apart
the String into an array of Variant(String). Excel will piece together the
elements of the array to assemble the SQL statement.
For example, assign the result of the following function to the CommandText
property, passing your SQL text as the argument to the function.
Public Function SplitString(ByVal strCommandText As String) As Variant
Dim varCommandText() As Variant
Dim i As Long
ReDim varCommandText(0 To Len(strCommandText) \ 255) ' note: it is not 256
For i = 0 To UBound(varCommandText)
varCommandText(i) = Mid(strCommandText, i * 255 + 1, 255)
Next
SplitString = varCommandText
End Function
There appears to be an undocumented limitation on the Let procedure behind
the CommandText property on the Excel.PivotCache class.
When getting the property, a String value is returned, not a Variant(String)
type as noted in the documentation. This string contains the SQL text in the
PivotCache. The string is not limited to 255 characters in length.
When setting (letting) the property, you can pass it a string of length less
than or equal to 255 characters. If you pass a longer string, VBA raises an
runtime error 1004.
There is a workaround: instead of passing a String type value, break apart
the String into an array of Variant(String). Excel will piece together the
elements of the array to assemble the SQL statement.
For example, assign the result of the following function to the CommandText
property, passing your SQL text as the argument to the function.
Public Function SplitString(ByVal strCommandText As String) As Variant
Dim varCommandText() As Variant
Dim i As Long
ReDim varCommandText(0 To Len(strCommandText) \ 255) ' note: it is not 256
For i = 0 To UBound(varCommandText)
varCommandText(i) = Mid(strCommandText, i * 255 + 1, 255)
Next
SplitString = varCommandText
End Function