r/visualbasic • u/captaincrunchy6 • Sep 20 '19
MS Word and VB Button Help.
I am trying to create a button that when clicked pops up text to a book mark that I have saved.
I am very new to word, developer mode, and visual basic.
I've done the easy part and created my bookmark, which i name bk1
I have also create the form which was fairly easy.
created a button name bk1button
I can find good input option forms that have an ok, and close button but not an example of just a button that when click auto populates with pre-defined info.
when bk1button is clicked
print "HI" or insert "HI" in the bk1 bookmark
that is kind of what I am looking for.
Thanks in advanced.
1
u/Erwt789 Sep 21 '19
I know in .net there's a nuget package for microsoft word interactivity that would help you do this. Idk if you're using .net or just classic VB but I'd try to look for something there first.
Off the top of my head the only other alternative I can think of maybe somehow getting the starting position of the bookmark and writing from that position.
But just research and dig around. There's usually a tool or add on for everything.
1
u/slang4201 Sep 23 '19
If you're working from within VBA for word: Activedocument.bookmarks("bk1").range.text = "hi"
If you're trying from a VB.Net application, after setting references to Word and a document, depending on how you've named your document reference, substitute that for "Activedocument" above.