Is txtname.text a value, or a string? the CStr function expects a value.

You could replace that line with:
sheet1.Range("B4").Value = format(txtname.Text,"@")
Which would then cope with being passed either a value or a string.