Problem with combobox initialization in UserForm

User avatar
Charles Kenyon
5StarLounger
Posts: 623
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Problem with combobox initialization in UserForm

Post by Charles Kenyon »

Here is a link to a template Add-In I am working on.
https://www.dropbox.com/s/3zgcudrq2nwy9 ... .dotm?dl=0

Here is what the form looks like before initialization.
00 deleteme 9.png
I have made the Styles width parts invisible for now because that does not work. Here is what it looks like after initialization.
00 deleteme 1.png
I have commented out a line in the initialization code that throws a type mismatch error.
Here is the initialization code:

Code: Select all

Private Sub UserForm_Initialize()
    lblNavPaneSettings.Caption = "This dialog is from the Add-In " & _
        ThisDocument.Name & vbCr & "stored in your Word StartUp Folder: " & vbCr & _
        Application.StartupPath
    cbxSetWidth.Value = ThisDocument.Variables("SetNavPaneWidth").Value
    cbxShowNavPane.Value = ThisDocument.Variables("NavState").Value
    cbxShowStyles.Value = ThisDocument.Variables("StylesState").Value
    cmbWidth.List = Array("100", "150", "200", "250", "300", "350", "400", "450")
    cmbStylesWidth.List = Array("100", "150", "200", "250", "300", "350", "400", "450")
    cmbStylesWidth.Visible = False  ' until I get fixed
    cmbWidth.Value = ThisDocument.Variables("NavPaneWidth")
'    cmbStylesWidth.Value = ThisDocument.Variables("StylesPaneWidth") ' throws error
    lblWidthExplain.Caption = "Pick or type width." & vbCr & " - The default setting in Word 2019 is about 400."
    lblCopyright.Caption = "Copyright " & ThisDocument.CustomDocumentProperties("Copyright") & _
        " Charles Kenyon, Sun Prairie, WI, USA." & _
        vbCr & "Version " & ThisDocument.CustomDocumentProperties("Version")
End Sub
I do not currently need this since vba in Word 365 is not allowing setting of the width. (No error, just ignores it.)
However, the commands for initializing the comboboxes for the Navigation Pane and the Styles Pane are identical. In both cases, the document variable being called upon is an integer. For the combobox for the styles pane (if not commented out) I get a type mismatch error message.
00 deleteme 6.png
Eventually I hope MS will address being able to change the width of the Styles Pane in vba so I can implement the rest. In the meantime, I am curious.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Problem with combobox initialization in UserForm

Post by HansV »

To investigate the problem, I tried to view ThisDocument.Variables("StylesPaneWidth"). It turns out that this Variable does not exist. The available Variables are:

StylesState
SetStylesPaneWidth
SetNavPaneWidth
NavState
NavPaneWidth
Author

If you add the Variable StylesPaneWidth by running the macro

Code: Select all

Sub Init()
    ThisDocument.Variables.Add Name:="StylesPaneWidth", Value:=200
End Sub
(200 is just an arbitrary value), then the userform initialization will run without error after uncommenting the line

Code: Select all

'    cmbStylesWidth.Value = ThisDocument.Variables("StylesPaneWidth")
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Problem with combobox initialization in UserForm

Post by HansV »

P.S. You have a stray End With in Private Sub NavPaneWidth(), and in another procedure you have UserFormClick instead of UserForm_Click
Best wishes,
Hans

User avatar
Charles Kenyon
5StarLounger
Posts: 623
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Problem with combobox initialization in UserForm

Post by Charles Kenyon »

Thank you Hans.
I have corrected these defects. It now loads OK, the userform initializes and works.

It still will not activate the Styles Pane upon Word startup but will if the form is run after Word is open. I am posting a separate question about that.

User avatar
Charles Kenyon
5StarLounger
Posts: 623
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Problem with combobox initialization in UserForm

Post by Charles Kenyon »

For anyone interested, the Add-In can be downloaded from my downloads page.
https://addbalance.com/word/download.htm#NavPane
You do not have the required permissions to view the files attached to this post.