ExcelTip.com
Account Icon Account Icon Account Icon
ExcelTip.com

Go Back   Excel Help Forum > Usenet Groups > Excel 2007 Help

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-16-2008, 08:13 AM
sameerkm sameerkm is offline
Registered User
 
Join Date: 16 Jul 2008
Location: Abu Dhabi
Posts: 2
sameerkm is on a distinguished road
Text Box Orientation in Excel 2007

Dear Friends,

When you run the code below in Excel 2007 why does is the text written vertically although I have specified "msoTextOrientationHorizontal" and AutoSize = True. This code runs fine in Excel 2003. Does anybody have a solution to this? Please help.

Code:
Sub PlotTBox()

Dim dRectX As Double, dRectY As Double, dRectW As Double, dRectH As Double
Dim dStartPos As Double
Dim shTextBox As Shape
Dim strNameShort As String
            
dRectX = 50
dRectY = 50
dRectH = 14
dRectW = 14

strNameShort = "Horizontal Please"
            
            Set shTextBox = Sheet1.Shapes.AddTextbox(msoTextOrientationHorizontal, dRectX, dRectY, dRectW, dRectH)
            
            With shTextBox
                .TextFrame.AutoSize = True
                .TextFrame.Characters.Font.Size = 8
                .TextFrame.Characters.Font.Bold = True
                .TextFrame.Characters.Text = strNameShort
                .Line.Visible = msoFalse
                .Fill.Visible = msoFalse
                
            End With

End Sub

A similar problem was discussed in this thread. Since the text in the textbox changes I cannot give an exact width for the text box.

Thanks in advance.

Sameer.


Please use CODE tags rather than colour formatting the code.

Last edited by Andy Pope; 07-16-2008 at 05:08 PM.
Reply With Quote
  #2  
Old 07-16-2008, 05:09 PM
Andy Pope's Avatar
Andy Pope Andy Pope is offline
Forum Moderator
 
Join Date: 10 May 2004
Location: Essex, UK
Posts: 2,110
Andy Pope will become famous soon enough Andy Pope will become famous soon enough
Autosize now works for the height so you need to resize and check the number of lines.

Code:
Sub PlotTBox()

Dim dRectX As Double, dRectY As Double, dRectW As Double, dRectH As Double
Dim dStartPos As Double
Dim shTextBox As Shape
Dim strNameShort As String

dRectX = 50
dRectY = 50
dRectH = 14
dRectW = 14

strNameShort = "Horizontal Please"

Set shTextBox = Sheet1.Shapes.AddTextbox(msoTextOrientationHorizontal, dRectX, dRectY, dRectW, dRectH)

With shTextBox
.TextFrame.AutoSize = True
.TextFrame.Characters.Font.Size = 8
.TextFrame.Characters.Font.Bold = True
.TextFrame.Characters.Text = strNameShort
.Line.Visible = msoFalse
.Fill.Visible = msoFalse

Do While .TextFrame2.TextRange.Lines.Count > 1
    .Width = .Width + 2
    .TextFrame.AutoSize = True
Loop

End With

End Sub
__________________
Cheers
Andy
Reply With Quote
  #3  
Old 07-17-2008, 02:26 AM
sameerkm sameerkm is offline
Registered User
 
Join Date: 16 Jul 2008
Location: Abu Dhabi
Posts: 2
sameerkm is on a distinguished road
Dear Andy,

Thank you for the quick reply and showing me the workaround. Much appreciated.

Do you have any idea why this is happening , since the code runs fine in Excel 2003. Is it a bug? Had Microsoft announced this change?

Things like this is very frustrating if you have to change this in several pages of code.

Regards,

Sameer
Reply With Quote
  #4  
Old 07-17-2008, 05:26 AM
Andy Pope's Avatar
Andy Pope Andy Pope is offline
Forum Moderator
 
Join Date: 10 May 2004
Location: Essex, UK
Posts: 2,110
Andy Pope will become famous soon enough Andy Pope will become famous soon enough
Shapes and charts are completely new in xl2007.

The autosize no longer auto sizes on both the height and width but only the height.

It is not a bug as this is the new behaviour but it is a change.
__________________
Cheers
Andy
Reply With Quote
Reply

Bookmarks

New topics in Excel 2007 Help


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -4. The time now is 12:15 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0