2017-08-04 112 views
3

我希望評論框適合正確的評論(底部沒有額外的空間)。調整excel評論以適合具有特定寬度的文本

我知道有是.AutoSize但我想最大寬度爲300

這裏是我的代碼,

For Each mycell In myRng.Cells 
    If Not (mycell.Comment Is Nothing) Then 
     With mycell.Comment.Shape 
     .TextFrame.AutoSize = True 
     If .width > 300 Then 
      lArea = .width * .height 
      .width = 300 
      .height = (lArea/300) 
     End If 
     End With 
    End If 
Next mycell 

mycellmyRng是範圍的數據類型,lArea長。

現在,這項工作相對較好,但在許多評論的底部會留下額外空間,因爲自動調整文本佔用的區域與自動評估框的區域不同。

有沒有辦法檢查評論裏面的空白,然後修剪它?或者,我有最好的將會是什麼?

+0

也許嘗試'... Comment.Text = TRIM(... Comment.Text)'? – BruceWayne

+0

我有一個類似的問題,並通過編寫一個自動換行例程來解決它。所以評論是自動調整大小的,底部沒有額外的空白空間;寬度有限。 –

回答

2

試試這個...測試評論已被放置在小區E4

發現通過將Range("e4").Comment.Shape.TextFrame在監視窗口

Sub testComment() 

    With Range("e4").Comment.Shape 

     .TextFrame.AutoSize = True 

     lArea = .Width * .Height 

     .Width = 300 
     .Height = (lArea/.Width)  ' used .width so that it is less work to change final width 

     .TextFrame.AutoMargins = False 
     .TextFrame.MarginBottom = 0  ' margins need to be tweaked 
     .TextFrame.MarginTop = 0 
     .TextFrame.MarginLeft = 0 
     .TextFrame.MarginRight = 0 
    End With 
End Sub 
相關問題