ช่วยจัดระเบียบ VBA ให้กระชับและง่ายกว่านี้ทีครับ
Posted: Mon Nov 21, 2016 7:58 am
Code: Select all
Sub Macro2()
ActiveSheet.Shapes.Range(Array("เก่ง1")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(112, 48, 160)
.Transparency = 0
.Solid
End With
ActiveSheet.Shapes.Range(Array("เก่ง2")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With
ActiveSheet.Shapes.Range(Array("เก่งปี")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With
Range("e3").Select
End Sub
Sub Macro3()
ActiveSheet.Shapes.Range(Array("เก่ง1")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.Transparency = 0
.Solid
End With
ActiveSheet.Shapes.Range(Array("เก่ง2")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(112, 48, 160)
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With
ActiveSheet.Shapes.Range(Array("เก่งปี")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With
Range("e3").Select
End Sub
Sub Macro4()
ActiveSheet.Shapes.Range(Array("เก่ง1")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.Transparency = 0
.Solid
End With
ActiveSheet.Shapes.Range(Array("เก่ง2")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With
ActiveSheet.Shapes.Range(Array("เก่งปี")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(112, 48, 160)
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With
Range("e3").Select
End Sub
ถ้าหากว่า กดปุ่มใดๆ ปุ่มที่กดจะเป็นตัวอักษรสีม่วง
ส่วนปุ่มอื่นจะเป็นตัวอักษรสีขาว
VBA ชุดนี้ทำงานได้ปกติอยู่ครับ
แต่อยากให้ช่วยจัดระเบียบ VBA ให้กระชับและง่ายกว่านี้
เพื่อประโยชน์ในการเขียน VBA ประเภทนี้ต่อไปในอนาคตครับ
ขอบคุณครับ