• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

excelde css var mı ?

Katılım
14 Kasım 2017
Mesajlar
618
Excel Vers. ve Dili
2010 Türkçe
excelde html kodlama yada css kodlama yapılabiliyormu. Evet ise nasıl yapılıyor. şimdiden tşkler
 
excel de visual basic kodları çalışır. Buna makro deniyor =) web mantığı yoktur.
 
Aslında Exceldeki CSS excel hücrelerinin belli formatta ayarlama ve o formatta sabit kalmasını sağlama durumları var.

Örneğin

Kod:
Private Sub Worksheet_Change(ByVal Target As Range)
Range("A1:F1").Interior.Color = RGB(204, 229, 244) [B][COLOR="Red"]'A1:F1 hücre aralığındaki hücreleri belirtilen renk ile gösterir[/COLOR][/B]
Range("A1:F25").Borders.LineStyle = xlDash [COLOR="red"][B]'A1:F25 hücre arallığındaki hücrelerin kenar çizgilerinde kenarlık belirlenir[/B][/COLOR]
Range("A1:B1:C1:D1:E1:F1").Font.Bold = True '[B][COLOR="red"]belirtilen hücrelerdeki yazı fontunun kalın olmasını sağlar[/COLOR][/B]
Range("A1:B1:C1:D1:E1:F1").Font.Color = vbRed [B][COLOR="red"]'belirtilen hücrelerdeki verileri kırmızı renkte yazar[/COLOR][/B]
Range("A1:F25").HorizontalAlignment = xlLeft [COLOR="red"][B]'belirtilen hücrelerdeki verileri sola dayalı yazar[/B][/COLOR]
 
UserForm1 içine WebBrowser yerleştir ve test et

Kod:
Option Explicit
Dim guncellenecekSatir As Long

Private Sub UserForm_Initialize()
    guncellenecekSatir = 0
    Call HtmlArayuzYukle
End Sub

Sub HtmlArayuzYukle()
    Dim html As String
  
    ' HTML parçalarını birleştiriyoruz
    html = "<html><head><style>"
    html = html & "body { background: #f0f2f5; font-family: 'Segoe UI', Arial; padding: 15px; }"
    html = html & ".container { max-width: 500px; margin: auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }"
    html = html & ".row { display: flex; gap: 8px; margin-bottom: 12px; }"
    html = html & "input { flex: 1; height: 45px; padding: 10px; border: 2px solid #ddd; border-radius: 6px; font-size: 15px; }"
    html = html & ".btn { height: 45px; padding: 0 15px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; color: white; width: 100%; }"
    html = html & ".btn-ekle { background: #27ae60; }"
    html = html & ".btn-guncelle { background: #f39c12; display: none; }"
    html = html & "table { width: 100%; border-collapse: collapse; margin-top: 20px; }"
    html = html & "th, td { padding: 10px; text-align: left; border-bottom: 1px solid #eee; font-size: 13px; }"
    html = html & "th { background: #f8f9fa; }"
    html = html & ".islem-btn { padding: 4px 8px; border: none; border-radius: 4px; cursor: pointer; color: white; margin-right: 3px; }"
    html = html & ".sil { background: #e74c3c; } .edit { background: #3498db; }"
    html = html & "</style></head><body>"
    html = html & "<div class='container'><h3>Personel Paneli</h3>"
    html = html & "<div class='row'><input type='text' id='tAd' placeholder='Ad'><input type='text' id='tTel' placeholder='Tel'></div>"
    html = html & "<button id='bEkle' class='btn btn-ekle' onclick='document.title=""EKLE""'>Ekle</button>"
    html = html & "<button id='bGuncel' class='btn btn-guncelle' onclick='document.title=""OK""'>Güncelle</button>"
    html = html & "<div id='liste'></div></div></body></html>"

    WebBrowser1.Navigate "about:blank"
    DoEvents
    WebBrowser1.Document.Open
    WebBrowser1.Document.Write html
    WebBrowser1.Document.Close
    Call VerileriListele
End Sub

Sub VerileriListele()
    Dim i As Long, son As Long, tablo As String
    Dim sh As Worksheet: Set sh = Sheets("Sayfa1")
  
    son = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row
    tablo = "<table><tr><th>Ad</th><th>Tel</th><th>#</th></tr>"
  
    If son > 1 Then
        For i = 2 To son
            tablo = tablo & "<tr><td>" & sh.Cells(i, 1).Value & "</td><td>" & sh.Cells(i, 2).Value & "</td>"
            tablo = tablo & "<td><button class='islem-btn edit' onclick='document.title=""DU_" & i & """'>Düzenle</button>"
            tablo = tablo & "<button class='islem-btn sil' onclick='document.title=""SL_" & i & """'>Sil</button></td></tr>"
        Next i
    Else
        tablo = tablo & "<tr><td colspan='3'>Kayıt yok.</td></tr>"
    End If
  
    WebBrowser1.Document.getElementById("liste").innerHTML = tablo & "</table>"
End Sub

Private Sub WebBrowser1_TitleChange(ByVal Text As String)
    Dim d As Object: Set d = WebBrowser1.Document
    Dim s As Worksheet: Set s = Sheets("Sayfa1")
  
    If Text = "EKLE" Then
        Dim n As Long: n = s.Cells(s.Rows.Count, 1).End(xlUp).Row + 1
        s.Cells(n, 1).Value = d.getElementById("tAd").Value
        s.Cells(n, 2).Value = d.getElementById("tTel").Value
        Call Temizle(d)
    ElseIf Left(Text, 3) = "SL_" Then
        s.Rows(Mid(Text, 4)).Delete: Call VerileriListele
    ElseIf Left(Text, 3) = "DU_" Then
        guncellenecekSatir = Mid(Text, 4)
        d.getElementById("tAd").Value = s.Cells(guncellenecekSatir, 1).Value
        d.getElementById("tTel").Value = s.Cells(guncellenecekSatir, 2).Value
        d.getElementById("bEkle").Style.Display = "none"
        d.getElementById("bGuncel").Style.Display = "block"
    ElseIf Text = "OK" Then
        s.Cells(guncellenecekSatir, 1).Value = d.getElementById("tAd").Value
        s.Cells(guncellenecekSatir, 2).Value = d.getElementById("tTel").Value
        d.getElementById("bEkle").Style.Display = "block"
        d.getElementById("bGuncel").Style.Display = "none"
        Call Temizle(d)
    End If
    WebBrowser1.Document.Title = ""
End Sub

Sub Temizle(d As Object)
    d.getElementById("tAd").Value = "": d.getElementById("tTel").Value = ""
    guncellenecekSatir = 0: Call VerileriListele
End Sub
 

Ekli dosyalar

Son düzenleme:
Diğer bir örnek PullDown Menü Örneği Not; Userform'a WebBrowser ekle
Kod:
Dim SayfaYuklendi As Boolean ' Sayfa hazır olmadan makro tetiklenmesini engeller

Private Sub UserForm_Initialize()
    SayfaYuklendi = False ' Başlangıçta kilidi kapat
    Me.Width = 700
    Me.Height = 450
    Call BuyukMenuYukle
End Sub

Sub BuyukMenuYukle()
    Dim h As String
   
    ' HTML ve CSS - Büyük Yazı Tipleri ve Klasik Tasarım
    h = "<html><head><style>"
    h = h & "body { margin:0; padding:0; font-family:'Segoe UI', Tahoma, sans-serif; background:#d4d0c8; overflow:hidden; cursor:default; }"
   
    ' Menü Barı - Yüksekliği yazıya göre artırıldı
    h = h & ".menubar { background:#d4d0c8; height:35px; border-bottom:1px solid #808080; width:100%; position:relative; z-index:10; display:block; }"
   
    ' Ana Menü Başlıkları - Yazı boyutu 14px yapıldı
    h = h & ".menu-item { float:left; position:relative; padding:8px 18px; font-size:14px; font-weight:bold; color:black; border:1px solid transparent; user-select:none; }"
    h = h & ".menu-item:hover { border-top:1px solid #fff; border-left:1px solid #fff; border-right:1px solid #808080; border-bottom:1px solid #808080; background:#eee; }"
   
    ' Pulldown (Açılır Kutu) - Genişletildi
    h = h & ".dropdown { display:none; position:absolute; top:33px; left:0; background:#d4d0c8; min-width:200px; "
    h = h & "border:1px solid #808080; z-index:999; padding:5px; box-shadow: 4px 4px 8px rgba(0,0,0,0.3); }"
   
    ' Alt Menü Linkleri - Yazı boyutu 13px yapıldı
    h = h & ".dropdown a { display:block; padding:8px 25px; text-decoration:none; color:black; font-size:13px; clear:both; border-bottom:1px solid #c0c0c0; }"
    h = h & ".dropdown a:hover { background:#000080; color:white; }"
   
    h = h & "</style>"
   
    ' JavaScript - ID Bazlı Kararlı Kontrol
    h = h & "<script type='text/javascript'>"
    h = h & "function ac(id) {"
    h = h & "  var d1 = document.getElementById('m1');"
    h = h & "  var d2 = document.getElementById('m2');"
    h = h & "  var d3 = document.getElementById('m3');"
    h = h & "  var hedef = document.getElementById(id);"
    h = h & "  var suAnki = hedef.style.display;"
   
    ' Hepsini kapat
    h = h & "  if(d1) d1.style.display = 'none';"
    h = h & "  if(d2) d2.style.display = 'none';"
    h = h & "  if(d3) d3.style.display = 'none';"
   
    ' Tıklananı aç/kapat
    h = h & "  if(suAnki !== 'block') { hedef.style.display = 'block'; }"
    h = h & "  if(window.event) window.event.cancelBubble = true;"
    h = h & "}"
   
    ' Boşluğa tıklayınca kapat
    h = h & "document.onclick = function() {"
    h = h & "  var d1 = document.getElementById('m1'); if(d1) d1.style.display = 'none';"
    h = h & "  var d2 = document.getElementById('m2'); if(d2) d2.style.display = 'none';"
    h = h & "  var d3 = document.getElementById('m3'); if(d3) d3.style.display = 'none';"
    h = h & "};"
    h = h & "</script></head><body>"

    ' --- MENÜ GÖVDESİ ---
    h = h & "<div class='menubar'>"
   
    h = h & "  <div class='menu-item' onclick='ac(""m1"")'>DOSYA"
    h = h & "    <div id='m1' class='dropdown'>"
    h = h & "      <a onclick='document.title=""M_KAYDET""'>Dosyayı Kaydet</a>"
    h = h & "      <a onclick='document.title=""M_YAZDIR""'>Yazıcıya Gönder</a>"
    h = h & "      <a onclick='document.title=""M_CIKIS""'>Programdan Çık</a>"
    h = h & "    </div>"
    h = h & "  </div>"
   
    h = h & "  <div class='menu-item' onclick='ac(""m2"")'>DÜZENLE"
    h = h & "    <div id='m2' class='dropdown'>"
    h = h & "      <a onclick='document.title=""M_KES""'>Kes</a>"
    h = h & "      <a onclick='document.title=""M_KOPYA""'>Kopyala</a>"
    h = h & "      <a onclick='document.title=""M_YAPISTIR""'>Yapıştır</a>"
    h = h & "    </div>"
    h = h & "  </div>"
   
    h = h & "  <div class='menu-item' onclick='ac(""m3"")'>GÖRÜNTÜ"
    h = h & "    <div id='m3' class='dropdown'>"
    h = h & "      <a onclick='document.title=""M_YENILE""'>Sayfayı Yenile</a>"
    h = h & "      <a onclick='document.title=""M_TAM""'>Tam Ekran Modu</a>"
    h = h & "    </div>"
    h = h & "  </div>"
   
    h = h & "</div>"
    h = h & "</body></html>"

    WebBrowser1.Navigate "about:blank"
    DoEvents
    WebBrowser1.Document.Open
    WebBrowser1.Document.Write h
    WebBrowser1.Document.Close
   
    ' Sayfa tamamen yüklendi, artık makrolar tetiklenebilir
    SayfaYuklendi = True
End Sub

Private Sub WebBrowser1_TitleChange(ByVal Text As String)
    ' Kilit mekanizması: Sayfa yüklenmeden gelen sinyalleri reddet
    If Not SayfaYuklendi Or Text = "" Or Text = "about:blank" Then Exit Sub
   
    Select Case Text
        Case "M_CIKIS": Unload Me
        Case "M_KAYDET":
            ThisWorkbook.Save
            MsgBox "Excel Başarıyla Kaydedildi.", vbInformation, "Sistem"
        Case Else:
            MsgBox "Makro Çalıştırıldı: " & Text, vbInformation, "VBA Onay"
    End Select
   
    ' Başlığı temizle (Çok önemli: Tekrar tıklanabilirlik sağlar)
    WebBrowser1.Document.Title = ""
End Sub
 
Geri
Üst