sharpnado
sharpnado

Reputation: 79

Make Label Dynamic on Excel VBA

how can I make the entry of a Label field in Excel Dynamic? What I want is, when I open up the excel file my username will show up on the dynamic label field. on a Excel 5.0 Dialog.

enter image description here

Upvotes: 0

Views: 1928

Answers (2)

Mikael Kajander
Mikael Kajander

Reputation: 187

Use this to bind the value to username and Workbook_Open event. Just make sure you have the right name in "Label 1".

Private Sub Workbook_Open()
    Worksheets("YourSheetName").Shapes("Label 1").TextFrame.Characters.Text = Environ("Username")
End Sub

Place it in VBA.Project ThisWorkbook

This where you find the name of the label:

enter image description here

Upvotes: 1

dwirony
dwirony

Reputation: 5450

Place this in the sheet specific module - this will dynamically change Label 1's caption whenever something on the worksheet changes:

Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.Shapes("Label 1").TextFrame.Characters.Text = Range("A1").Value
End Sub

Upvotes: 1

Related Questions