Results 1 to 3 of 3

Thread: Newbie - Help - VBA script

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    2

    Question Newbie - Help - VBA script

    Hi,

    I am a newbie and was hoping for some help. I have an existing word 2010 document, what I would like to do is get people to either accept or reject (i.e. Click Yes or No) to my Terms & Conditions before opening that Word document.

    I have used the below code as a test and it works great. But now instead of a pop up box. I need something slightly bigger where I can show the entire Terms & Conditions statement.

    What I have in mind is, a pop-up form/box that shows the entire T&C statement but with a scroll bar so that users are not overwhelmed. Then, simply click Yes or No.

    Thanks in advance.

    Private Sub Document_Open()

    Dim wdApp As Word.Application
    Set wdApp = GetObject(, "Word.Application")

    Dim TermsConditions As String

    TermsConditions = MsgBox("Greetings", vbYesNo, "Greetings")

    If (TermsConditions = vbYes) Then
    Exit Sub

    ElseIf (TermsConditions = vbNo) Then
    wdApp.ActiveDocument.Close


    End If


    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Newbie - Help - VBA script

    add a userform with a textbox and a couple of commandbuttons, in the document_open, you can show the userform so it conceals the entire document, either make the userform bigger or the application window smaller, you can resize on closing the userform

    in the yes button have unload me, to close the form
    in the no button, thisdocument.close, i think the form will close anyway, but if not add unload me

    fyi the procedure you posted could be
    Code:
    Private Sub Document_Open()
    
    Dim TermsConditions As INTEGER
    
    TermsConditions = MsgBox("Greetings", vbYesNo, "Greetings")
    
    If (TermsConditions = vbNo) Then
       ThisDocument.Close
    End If
    
    End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    2

    Re: Newbie - Help - VBA script

    Thanks westconn1. I'll give this a go.

Posting Permissions

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



Click Here to Expand Forum to Full Width