Results 1 to 4 of 4

Thread: Help please - userform not coming up

  1. #1

    Help please - userform not coming up


    I'm verturing into my first attempts at some simple coding with userforms and have been followinf various examples and tutorials online. However my 'test' just refuses to display the userform I have created.

    I have this in the userform (named MyForm) part of the project

    Option Explicit

    Private Sub cmdSubmit_Click()
    FillBM "Test", txttest.Text
    Unload Me
    End Sub

    Private Sub FillBM(strBMName As String, strValue As String)
    Dim orng As Range
    With ActiveDocument
    Application.ScreenUpdating = False
    On Error GoTo lbl_Exit
    Set orng = .Bookmarks(strBMName).Range
    orng.Text = strValue
    orng.Bookmarks.Add strBMName
    End With
    Application.ScreenUpdating = True
    Set orng = Nothing
    Exit Sub
    End Sub

    Private Sub cmdCancel_Click()
    ActiveDocument.Close SaveChanges:=False

    End Sub

    And this in the Module (named modMain)

    Sub AutoNew()
    Exit Sub
    End Sub

    And this in the Thus Document part (although I also tried sticking it in the ModMain as well)

    Option Explicit

    Sub CallUF()
    Dim oFrm As MyForm
    Set oFrm = New MyForm
    Unload oFrm
    Set oFrm = Nothing
    Exit Sub
    End Sub

    The AutoNew works fine and creates a new document and the macro CallUf is there (and I can run in manually) but why won't it start automatically when I create a new doc from the template?

    Any help would be appreciated


    Oh - here is the whole thing if it helps


  2. #2
    For a start this isn't a template but a macro enabled document. It would be better saved as a macro enabled template if you plan to create documents from it.
    The Sub CallUF() should be in the ModMain module. It contains code that is not referenced anywhere i.e. Create_Reset_Variables so that line should be removed.
    The userform code will crash on the cancel button

    Change the Cancel code as follows
    Private Sub cmdCancel_Click()
        ActiveDocument.Close SaveChanges:=False
    End Sub
    It will then work when you create a new document from the template - File > New
    As your document contains some of my code see
    and the code in the Help template I posted there.
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes

  3. #3
    Fantastic - thanks Graham,

    Now, being new to all this, how do I mark the thread as solved?

  4. #4
    Don't worry - found it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts