امين اسماعيلي
2014/05/05, 06:03
با درود
از همه دوستانی که این مدت نبودم معذرت میخوام . خوب حالم خوب نبود دعوام نکنین حاله دیگه خراب میشه. خوب بریم سر قصه امشب
شاید برای همه ما پیش اومده باشه که بخواهیم کد رنگ ها و فونت ها و ...... رو در ویژوال به درستی به کار ببریم و از کد اون مطلع نباشیم . کد زیر یه شیت براتون ایجاد میکنه و مشکلتون رو حل میکنه .
Sub colors()
ActiveWorkbook.Sheets.Add
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Range("A1:H1").Value = Array("interior", "font", "HTML", "bgcolor=", "Red", "Green", "Blue", "Color")
Range("E1").Font.ColorIndex = 3
Range("F1").Font.ColorIndex = 4
Range("G1").Font.ColorIndex = 5
Range("A2").Font.ColorIndex = 2
Range("D2").Font.ColorIndex = 2
Range("H2").Font.ColorIndex = 2
Dim i As Long
Dim str0 As String, str As String
For i = 1 To 56
Cells(i + 1, 1).Interior.ColorIndex = i
Cells(i + 1, 1).Value = "[Color " & i & "]"
Cells(i + 1, 2).Font.ColorIndex = i
Cells(i + 1, 2).Value = "[Color " & i & "]"
str0 = Right("000000" & Hex(Cells(i + 1, 1).Interior.Color), 6)
'Excel shows nibbles in reverse order so make it as RGB
str = Right(str0, 2) & Mid(str0, 3, 2) & Left(str0, 2)
'generating 2 columns in the HTML table
Cells(i + 1, 3) = "#" & str
Cells(i + 1, 4) = "#" & str
Cells(i + 1, 4).Interior.ColorIndex = i
Cells(i + 1, 5).Formula = "=Hex2dec(""" & Right(str0, 2) & """)"
Cells(i + 1, 6).Formula = "=Hex2dec(""" & Mid(str0, 3, 2) & """)"
Cells(i + 1, 7).Formula = "=Hex2dec(""" & Left(str0, 2) & """)"
Cells(i + 1, 8) = "[Color " & i & "]"
Next i
Range("H2").Value = "vbBlack"
Range("H2").Interior.Color = vbBlack
Range("H3").Value = "vbWhite"
Range("H3").Interior.Color = vbWhite
Range("H4").Value = "vbRed"
Range("H4").Interior.Color = vbRed
Range("H5").Value = "vbGreen"
Range("H5").Interior.Color = vbGreen
Range("H6").Value = "vbBlue"
Range("H6").Interior.Color = vbBlue
Range("H7").Value = "vbYellow"
Range("H7").Interior.Color = vbYellow
Range("H8").Value = "vbMagenta"
Range("H8").Interior.Color = vbMagenta
Range("H9").Value = "vbCyan"
Range("H9").Interior.Color = vbCyan
done:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
خوب خوب با این اعداد اشنا بشین . یه ماژوا ایجاد کنید . دیگه توضیح نمیدم قبلا روش ایجاد ماژول تو محیط VBA گفته شد . بعدش کد های زیر رو در انجا کپی و RUN کنید ( F5 )
در ادامه شب های بعد در همین تاپیک با کد نویسی با این اعداد بیشتر اشنا میشیم.
از همه دوستانی که این مدت نبودم معذرت میخوام . خوب حالم خوب نبود دعوام نکنین حاله دیگه خراب میشه. خوب بریم سر قصه امشب
شاید برای همه ما پیش اومده باشه که بخواهیم کد رنگ ها و فونت ها و ...... رو در ویژوال به درستی به کار ببریم و از کد اون مطلع نباشیم . کد زیر یه شیت براتون ایجاد میکنه و مشکلتون رو حل میکنه .
Sub colors()
ActiveWorkbook.Sheets.Add
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Range("A1:H1").Value = Array("interior", "font", "HTML", "bgcolor=", "Red", "Green", "Blue", "Color")
Range("E1").Font.ColorIndex = 3
Range("F1").Font.ColorIndex = 4
Range("G1").Font.ColorIndex = 5
Range("A2").Font.ColorIndex = 2
Range("D2").Font.ColorIndex = 2
Range("H2").Font.ColorIndex = 2
Dim i As Long
Dim str0 As String, str As String
For i = 1 To 56
Cells(i + 1, 1).Interior.ColorIndex = i
Cells(i + 1, 1).Value = "[Color " & i & "]"
Cells(i + 1, 2).Font.ColorIndex = i
Cells(i + 1, 2).Value = "[Color " & i & "]"
str0 = Right("000000" & Hex(Cells(i + 1, 1).Interior.Color), 6)
'Excel shows nibbles in reverse order so make it as RGB
str = Right(str0, 2) & Mid(str0, 3, 2) & Left(str0, 2)
'generating 2 columns in the HTML table
Cells(i + 1, 3) = "#" & str
Cells(i + 1, 4) = "#" & str
Cells(i + 1, 4).Interior.ColorIndex = i
Cells(i + 1, 5).Formula = "=Hex2dec(""" & Right(str0, 2) & """)"
Cells(i + 1, 6).Formula = "=Hex2dec(""" & Mid(str0, 3, 2) & """)"
Cells(i + 1, 7).Formula = "=Hex2dec(""" & Left(str0, 2) & """)"
Cells(i + 1, 8) = "[Color " & i & "]"
Next i
Range("H2").Value = "vbBlack"
Range("H2").Interior.Color = vbBlack
Range("H3").Value = "vbWhite"
Range("H3").Interior.Color = vbWhite
Range("H4").Value = "vbRed"
Range("H4").Interior.Color = vbRed
Range("H5").Value = "vbGreen"
Range("H5").Interior.Color = vbGreen
Range("H6").Value = "vbBlue"
Range("H6").Interior.Color = vbBlue
Range("H7").Value = "vbYellow"
Range("H7").Interior.Color = vbYellow
Range("H8").Value = "vbMagenta"
Range("H8").Interior.Color = vbMagenta
Range("H9").Value = "vbCyan"
Range("H9").Interior.Color = vbCyan
done:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
خوب خوب با این اعداد اشنا بشین . یه ماژوا ایجاد کنید . دیگه توضیح نمیدم قبلا روش ایجاد ماژول تو محیط VBA گفته شد . بعدش کد های زیر رو در انجا کپی و RUN کنید ( F5 )
در ادامه شب های بعد در همین تاپیک با کد نویسی با این اعداد بیشتر اشنا میشیم.