View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Walter Briscoe Walter Briscoe is offline
external usenet poster
 
Posts: 279
Default Porting from Excel 2003 to Excel 2010

In message of Sat, 2 Aug 2014 06:07:09 in
microsoft.public.excel.programming, GS writes
So far I found in 2003/2010 ObjectBrowser...

ShapeTextFrameAutoMargins

..is a common property of type Boolean. Perhaps the issue is that of
using a fully qualified ref to the specific 'Shape' object in question?


Why might that be a problem? How would I access it otherwise?

I now have some code which "seems to work" in both Excel 2003 and 2010.

I simplified my driving code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 01/08/2014 by IBM
'

'
Dim sh As Shape
If ActiveSheet.Shapes.Count < 0 Then ActiveSheet.Shapes(1).Delete
Set sh = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHo rizontal, 195#, 107.25, 164.25, 87#)
sh.TextFrame.Characters.Text = "Hello, World"

ShowShapes
Stop
End Sub

I removed the On Error logic from Function ShapeText and put some
version specific code in place.
It is GOOD to be rid of error handling code. ;)
It is POOR to have version specific code. ;(

Private Function ShapeText(ByVal v As Shape) As String
Dim s As String
Dim i As Long
Dim j As Long
Dim TF As TextFrame
Dim Ch As Characters

Set TF = v.TextFrame
With TF
If Application.Version = "14.0" Then
s = "Un, " ' Automargins does not seem defined in Excel 2010
Else
s = IIf(.AutoMargins, "Tr, ", "Fa, ")
End If
s = s & IIf(.AutoSize, "Tr, ", "Fa, ")
s = s & "M(" & .MarginLeft & "," & .MarginTop & "," & _
.MarginRight & "," & .MarginBottom & ") "
Set Ch = .Characters
If Ch.Text = "" Then ShapeText = s & "NO TEXT": Exit Function
With Ch.Font
s = s & "F(" & .FontStyle & "," & .Name & "," & .Size & "): """
End With
j = Ch.Count
' Text limits itself to 255 bytes in 2003. Safe limit not checked in 2010
For i = 1 To j Step 255
s = s & .Characters(Start:=i).Text
Next i
End With
s = s & """"
ShapeText = s
End Function

Characters is a curious member of TextFrame, behaving as both a Property
and a Method.
I find it a pity that View\Locals does not show it as a Property.

I am now comfortable that I can move on to the next porting issue.
Thanks to both Claus and Garry.
--
Walter Briscoe