Celso R
Celso R

Reputation: 1

How to apply a Quick Style from Word's Style Gallery directly to a Label in a VBA UserForm?

am developing a VBA UserForm where the user can select formatting options for a text. The text is displayed in a Label called lblFontPreview within the form.

I want to apply a specific style, called "Versalete", which is already configured in Word's Quick Styles Gallery, directly to the text displayed in the Label. I have confirmed that the "Versalete" style is properly configured in Word and can be applied manually in documents.

What I have tried: 1 - Checking if the style exists in the active Word document and is set as a Quick Style:

styleExists = ActiveDocument.Styles("Versalete").QuickStyle

2 - Applying the style to a temporary Range in Word and retrieving the text:

Set rng = ActiveDocument.Content
rng.Text = "Test Text"
rng.Style = ActiveDocument.Styles("Versalete")
lblFontPreview.Caption = rng.Text
rng.Delete

3 - Manually simulating the style properties in the Label (e.g., font, size, bold), but this doesn't fully meet my requirements as I want to use the exact style configured in Word. The Problem: The text displayed in the Label does not reflect the "Versalete" style from Word's Quick Styles Gallery. It only shows plain text without the visual formatting of the style.

My Question:

  1. Is it possible to directly apply a Quick Style from Word's Style Gallery to the text displayed in a Label in a VBA UserForm?
  2. If this is not directly possible, is there an efficient way to capture the visual formatting of the Word style and apply it to a control in the UserForm?

Upvotes: 0

Views: 33

Answers (0)

Related Questions