PDA

View Full Version : Open document / Auto. launch macro to capture text / Auto. modifications to text



sb003848
05-07-2014, 05:58 AM
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?

fumei
05-07-2014, 03:50 PM
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?

Jay Freedman
05-07-2014, 05:49 PM
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.