關於跨欄置中和框線畫線是否有比較簡易的寫法(謝謝各位大大,已解決。)
- 帖子
- 710
- 主題
- 280
- 精華
- 0
- 積分
- 1016
- 點名
- 0
- 作業系統
- Windows 10
- 軟體版本
- Office 2019
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2011-6-30
- 最後登錄
- 2025-1-19
|
關於跨欄置中和框線畫線是否有比較簡易的寫法(謝謝各位大大,已解決。)
本帖最後由 av8d 於 2012-4-27 08:12 編輯
首先A1:H1和A2:H2欄取消跨欄置中- Range("A1:G1").Select
- With Selection
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = False
- End With
- Selection.Merge
- Range("A2:G2").Select
- With Selection
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = False
- End With
- Selection.Merge
- End Sub
複製代碼 然後是A1:G1和A2:G2跨欄置中- Range("A1:H1").Select
- With Selection
- .HorizontalAlignment = xlGeneral
- .VerticalAlignment = xlCenter
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = True
- End With
- Selection.UnMerge
- Range("A2:H2").Select
- With Selection
- .HorizontalAlignment = xlGeneral
- .VerticalAlignment = xlCenter
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = True
- End With
- Selection.UnMerge
複製代碼 然後A1:G2框線畫右線- Range("A1:G2").Select
- Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With Selection.Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- Selection.Borders(xlInsideVertical).LineStyle = xlNone
- With Selection.Borders(xlInsideHorizontal)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- End Sub
複製代碼 |
|
|
|
|
|
|
- 帖子
- 1572
- 主題
- 16
- 精華
- 2
- 積分
- 1521
- 點名
- 0
- 作業系統
- xp
- 軟體版本
- office 2003
- 閱讀權限
- 150
- 性別
- 男
- 註冊時間
- 2010-5-1
- 最後登錄
- 2016-1-13

|
2#
發表於 2012-4-24 10:56
| 只看該作者
對於錄製的代碼,你應該把滑鼠放在每一行上按F1,查看它是做什麼用的
然後你就知道哪些語句是用不到的了。
拿來用的代碼對學習無多大幫助。 |
|
|
|
|
|
|
- 帖子
- 967
- 主題
- 0
- 精華
- 0
- 積分
- 1001
- 點名
- 0
- 作業系統
- WIN XP
- 軟體版本
- OFFICE 2003
- 閱讀權限
- 50
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-11-29
- 最後登錄
- 2022-5-17
 
|
3#
發表於 2012-4-24 12:57
| 只看該作者
回復 1# av8d - Sub aa()
- [A1:G1].Merge
- [A1:G1].HorizontalAlignment = xlCenter
- [A2:G2].Merge
- [A2:G2].HorizontalAlignment = xlCenter
- End Sub
- Sub bb()
- [A1:G1].UnMerge
- [A2:G2].UnMerge
- End Sub
- Sub cc()
- [A1:G2].Borders.LineStyle = xlContinuous
- End Sub
複製代碼 |
|
|
|
|
|
|
- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
4#
發表於 2012-4-24 13:13
| 只看該作者
回復 1# av8d - Sub Ex()
- Dim xi As Integer
- For xi = 2 To 10 Step 2
- With Range("A1:C1,E1:G1").Offset(xi)
- .Merge
- .HorizontalAlignment = xlCenter
- .Borders.LineStyle = xlContinuous
- End With
- Next
- End Sub
複製代碼 |
|
|
|
|
|
|
- 帖子
- 51
- 主題
- 0
- 精華
- 0
- 積分
- 81
- 點名
- 0
- 作業系統
- Win 7
- 軟體版本
- Office 2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2012-3-9
- 最後登錄
- 2013-1-9
|
5#
發表於 2012-4-24 19:05
| 只看該作者
本帖最後由 alexliou 於 2012-4-24 19:09 編輯
在一張工作表裡
可能有好幾個地方要畫粗外框線和跨欄置中
我現在都將畫框線和跨欄置中寫成 函式
引數是 Range 物件
每次要畫框線或跨欄置中時
就去呼叫函式 ex. Call 畫粗外框(Range("A1:A10"))
省得重複一堆 Code |
|
Alex
|
|
|
|
|
- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
6#
發表於 2012-4-24 20:32
| 只看該作者
回復 5# alexliou
可以貼上程式碼 分享嗎? |
|
|
|
|
|
|
- 帖子
- 51
- 主題
- 0
- 精華
- 0
- 積分
- 81
- 點名
- 0
- 作業系統
- Win 7
- 軟體版本
- Office 2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2012-3-9
- 最後登錄
- 2013-1-9
|
7#
發表於 2012-4-24 21:21
| 只看該作者
回復 6# GBKEE
這只是把畫粗外框的code集合在一起而已
Sub 畫粗外框(oRrange As Range)
oRange.Borders(xlDiagonalDown).LineStyle = xlNone
oRange.Borders(xlDiagonalUp).LineStyle = xlNone
With oRange.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlMedium
End With
With oRange.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlMedium
End With
With oRange.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlMedium
End With
With oRange.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlMedium
End With
oRange.Borders(xlInsideVertical).LineStyle = xlNone
oRange.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub
如要更彈性一點, 可將框線的粗細,顏色都設成引數 |
|
Alex
|
|
|
|
|
- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
8#
發表於 2012-4-25 07:09
| 只看該作者
回復 7# alexliou
簡化一下- Option Explicit
- Sub 畫粗外框(oRange As Range)
- Dim xi As Integer
- With oRange
- .Borders(5).LineStyle = xlNone '右斜線
- .Borders(6).LineStyle = xlNone '左斜線
- For xi = 7 To 10 '外框: 左>上>下>右
- With .Borders(xi)
- .LineStyle = xlContinuous
- .ColorIndex = 3
- .Weight = xlMedium
- End With
- Next
- If .Columns.Count > 1 Then '直線 需兩欄以上
- With .Borders(11)
- .LineStyle = 1 '
- .ColorIndex = 3
- End With
- End If
- If .Rows.Count > 1 Then '橫線 需兩列以上
- With .Borders(12)
- .LineStyle = 1
- .ColorIndex = 3
- End With
- End If
- End With
- End Sub
複製代碼 |
|
|
|
|
|
|
- 帖子
- 1572
- 主題
- 16
- 精華
- 2
- 積分
- 1521
- 點名
- 0
- 作業系統
- xp
- 軟體版本
- office 2003
- 閱讀權限
- 150
- 性別
- 男
- 註冊時間
- 2010-5-1
- 最後登錄
- 2016-1-13

|
9#
發表於 2012-4-25 08:01
| 只看該作者
本帖最後由 oobird 於 2012-4-25 08:02 編輯
- Sub yy()
- With Selection
- .Borders.LineStyle = 0
- .Borders.LineStyle = 1
- .Borders.ColorIndex = 5
- .BorderAround , 3, 5
- End With
- End Sub
複製代碼 可選取一個範圍,或同時選多個區域,一起給框線。內框為1,外框為3,5是顏色 |
|
|
|
|
|
|