Consulting

Results 1 to 3 of 3

Thread: Open document / Auto. launch macro to capture text / Auto. modifications to text

  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location

    Question Open document / Auto. launch macro to capture text / Auto. modifications to text

    I have a Word document that when opened, a MessageBox is shown asking to insert a text.

    Once the text is added to the TextBox (TextBox1), the user could either click on OK (to continue) or cancel (well, to cancel).

    If the user clicks on OK, I would like to have the text modified to change ' into ’ and then have the new text pasted (not sure if that is even a word) into the active document. This is what I have so far:
    Sub CommandButton1_Click()

    Unload Me
    End Sub

    Any ideas on what I need to add to make that happen?
    Last edited by sb003848; 05-07-2014 at 06:41 AM.

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    If the user clicks on OK, I would like to have the text modified to change ' into ’ and then have the new text pasted (not sure if that is even a word) into the active document.
    Modified how? Changed into what? Based on what rules? Pasted where?

  3. #3
    Try this:

    Private Sub CommandButton1_Click()
        Dim userText As String
        userText = Me.TextBox1.Text
        If Len(userText) > 0 Then
            userText = Replace(userText, Chr(39), Chr(146))
            Selection.Text = userText
        End If
        Unload Me
    End Sub
    You may want to change the Select.Text statement to put the text somewhere else in the document. As it is, it will replace any selected text with the string from the userform or, if the Selection is collapsed to a single point, it will insert the text there.

Posting Permissions

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