Private Sub UserForm_Activate()
Dim I&
TextBox1 = ""
If visibility Then
valider.Caption = "Quiter"
Me.Width = Table.Width * 1.2: Me.Height = Table.Height + 60
Me.WebBrowser1.Width = Me.InsideWidth
Me.WebBrowser1.Height = Table.Height + 10
voir.Top = Me.InsideHeight - 20
valider.Top = Me.InsideHeight - 20
End If
With WebBrowser1
.navigate "about:blank"
Do While .readystate < 4: DoEvents: Loop
.document.write "<html><body style=""margin:0;width:100%;height:100%;""><div id='calque' style=""width:100%;height:100%;"" contenteditable=true></div></body></html>"
Table.Copy
Set div = .document.getelementbyid("calque")
div.Focus
.ExecWB 13, 2 '--paste. don't prompt user.
Set dico = CreateObject("Scripting.Dictionary")
For Each cel In Table.Cells: dico(cel.MergeArea.Address(0, 0)) = "": Next
tMk = createTablemask(Table)
With .document.getelementsbytagname("TABLE")(0):
.Style.Width = Round(Table.Width) + 1 & "pt"
.Style.Height = Round(Table.Height) - 10 & "pt"
.Style.FontSize = ThisWorkbook.Styles(1).Font.Size & "pt"
nbligne = .getelementsbytagname("TR").Length
End With
Set tds = .document.getelementsbytagname("TD")
For Each EleM In dico
With Range(EleM)
tds(I).innerhtml = "<font>" & tds(I).innerhtml & "</font>"
tds(I).ChildNodes(0).Style.margin = "2pt"
VA = .VerticalAlignment: VA = Switch(VA = xlTop, "top", VA = xlBottom, "bottom", VA = xlCenter, "middle", IsNull(VA), "bottom")
ha = .HorizontalAlignment: ha = Switch(ha = xlLeft, "left", ha = xlCenter, "center", ha = xlRight, "right", IsNull(ha), "right")
tds(I).Style.TextAlign = IIf(IsNull(ha), "left", ha)
tds(I).Style.verticalalign = IIf(IsNull(VA), "bottom", VA)
If tds(I).colspan > 1 Or tds(I).rowspan > 1 Then
'tds(I).Style.Border = 0
End If
If .WrapText Then tds(I).Style.WORDBREAK = "break-all"
I = I + 1
End With
Next
I = 0
If OnlyText Then
cod = div.getelementsbytagname("TD")(0).innerhtml
Do
If InStr(1, cod, "class=") > 0 Then cod = Replace(cod, "class=font" & I, "") Else Exit Do
I = I + 1
Loop
div.innerhtml = cod
End If
End With
TextBox1 = div.innerhtml
'Debug.Print TextBox1
If visibility = False Then Me.Hide
'IE.ExecWB 17, 2 '-- select all. don't prompt user.
'IE.ExecWB 12, 2 '-- copy. don't prompt user.
End Sub