Ho provato anche ad inserire il codice nella modulo della UserForm ma niente, il codice viene ignorato.
Qualcuno mi saprebbe indicare come fare per associare il codice al pulsante sulla UserForm?
Grazie in anticipo e buona giornata.
- Codice: Seleziona tutto
Private Sub Inserisci_Anteprima()
Dim btn As Button, t As Range, Ur as Long
' Macro per inserire pulsante anteprima nel Foglio1
On Error Resume Next
Worksheets("Foglio1").Unprotect ""
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Ur = Worksheets("Foglio1").Range("B" & Rows.Count).End(xlUp).Row
Set t = Worksheets("Foglio1").Range(Cells(Ur + 4, 9), Cells(Ur + 5, 11))
Set btn = Worksheets("Foglio1").Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "Anteprima_stampa"
End With
With btn.Font
.Name = "Bookman Old Style"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With
btn.Font.Bold = True
btn.Characters.Text = "Anteprima_di_stampa"
With btn.Characters(Start:=1, Length:=19).Font
.Name = "Bookman Old Style"
.FontStyle = "Grassetto"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
With btn
.Locked = True
.LockedText = True
End With
With btn
.Placement = xlMove
.PrintObject = False
End With
Worksheets("Foglio1").Protect ""
Resume
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub