- 帖子
- 109
- 主題
- 1
- 精華
- 0
- 積分
- 116
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 2007
- 閱讀權限
- 20
- 註冊時間
- 2016-8-4
- 最後登錄
- 2018-10-22
 
|
回復 17# hong912
是2個事件,要放在同一個worksheet。按右鍵後會變色同時合併儲存格,如果在裡頭輸入,會有換列的效果(但不是很漂亮)。
個人覺得,如果會需要操作公式或程式,非必要盡量避免使用合併儲存格,儲存格合併之後,容易有很多奇奇怪怪的問題。- Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
- With Selection
- If .Interior.ColorIndex = 5 Then
- .Interior.ColorIndex = 3
-
- Else
- .Interior.ColorIndex = 5
- .Merge
- .WrapText = True
-
- End If
- End With
- End Sub
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim Vhight As Single
- If Target.WrapText = True Then
- With Target
- .Select
- .RowHeight = 1
- .WrapText = True
- .UnMerge
- .EntireRow.AutoFit
- Selection.Merge
- Vhight = .Width * .Height / Selection.Width
- If Vhight < 16 Then Vhight = 16
- .RowHeight = Vhight
- .VerticalAlignment = xlCenter
- End With
- End If
- End Sub
複製代碼 |
|