本帖最後由 C_Law 於 2017-2-27 17:01 編輯
是否想做到由 Column A 變做 Column B 的效果?
上圖由 Row 1 開始,用不同 Font size 做示範(10, 12, 14, 16....etc),不同 Font、Bold、Italic...etc 都得。
做法係加個 ActiveX 的 Label 落去張 Sheet,檢查個 Label 的 Width,太闊就縮短字串。
例如用 CommandButton1,Select Column A 的一個 Cell 之後 Click CommandButton1,就會根據 myWidth 的闊度縮短字串然後放在 Column B。- Private Sub CommandButton1_Click()
- Dim myWidth As Integer
- myWidth = 50
-
- Dim myRow As Integer
- myRow = ActiveCell.Row
-
- Label1.AutoSize = True
- Label1.WordWrap = False
- Label1.Visible = False
- Label1.Enabled = False
-
- Label1.Caption = Cells(myRow, 1)
- Label1.Font.Name = Cells(myRow, 1).Font.Name
- Label1.Font.Bold = Cells(myRow, 1).Font.Bold
- Label1.Font.Italic = Cells(myRow, 1).Font.Italic
- Label1.Font.Size = Cells(myRow, 1).Font.Size
-
- While (Label1.Width > myWidth And Len(Label1.Caption) > 1)
- Label1.Caption = Left(Label1.Caption, Len(Label1.Caption) - 1)
- Wend
-
- Cells(myRow, 2).Font.Name = Cells(myRow, 1).Font.Name
- Cells(myRow, 2).Font.Bold = Cells(myRow, 1).Font.Bold
- Cells(myRow, 2).Font.Italic = Cells(myRow, 1).Font.Italic
- Cells(myRow, 2).Font.Size = Cells(myRow, 1).Font.Size
- Cells(myRow, 2) = Label1.Caption
-
- End Sub
複製代碼 |