I have a document and I was wondering was there a way that I could type text onto the document and it gets copied into the text box i have created at real time. Thanks
Printable View
I have a document and I was wondering was there a way that I could type text onto the document and it gets copied into the text box i have created at real time. Thanks
well the closest I could get was this:
I cant find a "Keypress" event.... will keep looking though
VB Code:
Dim WithEvents WDoc As Word.Application Private Sub Form_Load() Dim wrd As New Word.Application wrd.Documents.Add Set WDoc = wrd.Application WDoc.Visible = True End Sub Private Sub Form_Unload(Cancel As Integer) WDoc.Quit End Sub Private Sub WDoc_WindowSelectionChange(ByVal Sel As Word.Selection) Text1 = Sel End Sub
Well i am now trying to copy text entered into the textbox and put it into the bookmark. I can get it working partially but it says it inserts before and is a pain. Is there anyway I can get it just to copy the normal text.
VB Code:
Private Sub Document_New() End Sub Private Sub TextBox1_Change() With ActiveDocument .Bookmarks("test1").range.InsertBefore TextBox1.Text End With End Sub
.Type
SOrry.. word is not my strong suit as far as Office goes...
what do you mean with .type?
I tried it instead of .Insertbefore but it created an error.
thanks alot static.
caz
wasnt sure...
I know when u record a macro in word and type some words.. it used blah.blah.type "words etc" or something like that.. worth a shot ;) sorry
try recording a macro.... and then look at the code (ALT+F11)
yeh i could try that but still got to make the link between the textbox and the bookmark which i can tdo without vba. Thanks anyway mate.
Here is the code i have just got but with the same errors for some reason and underneath is the output.
VB Code:
Private Sub TextBox1_Change() With ActiveDocument .Bookmarks("test1").range.Text = TextBox1.Text End With End Sub
Input in textbox: hello
Ouput at bookmark: hellohellhelheh
caz
The problem here is that the change event will fire off everytime you make a change so you type "h", bookmark = "h", you then type "e" so you have "he" in your text box, which again is added to the bookmark giving you "heh" and so on.
Not sure how you will get round this, but I'm sure someone can offer you some direction. Maybe you can fire the event with a keypress or a command button instead?
Thanks New2VBA, yeh that figures now. Making it on a vbKeySPace still had the problem with updating everything in the textbox.
Do you know anyway of using autocorrect in a document and showing both the old text and the changed text at the same time.
thanks for that.
caz
Sorry I don't, although if you search autocorrect in vba help there seems to be quite a lot of information, including examples.
DO you think i could send info from a bookmark into a textbox?
caz
solved thanks for all the help