Saabeirik
10-29-2012, 12:51 AM
Hi!
I'm making a word template with a userform that pops up when opening the document.
I write what I want into the textboxes, and this is in turn put into bookmarks in my document. Sometimes I want to edit some of the userform info, and I call my userform with a keyboard shortcut to update some of the textboxes. I then have some code to populate the textboxes with the bookmarks in the text, so that I don't have to write everything again, just edit what I want.
All of this works just fine when I'm in the template file. The problem occurs when I start a new document with this template. The userform is never populated with the bookmarks from this document, so every time I need to update information in the userform, I have to type in all of information again.
I guess the problem is that the userform is populated with the bookmark-text from my template file. Is this possible to solve in an easy way so that the userform is always populated with the bookmark text from the actual document?
The code I use for populating the userform is this, written in my template.
Private Sub UserForm_Activate()
inndata_ks.Firmanavn.Text = ThisDocument.Bookmarks("firmanavn").Range.Text
inndata_ks.utarbeidet_dato.Text = ThisDocument.Bookmarks("Utarbeidet_dato").Range.Text
inndata_ks.revisjon.Text = ThisDocument.Bookmarks("revisjon").Range.Text
End Sub
I'm making a word template with a userform that pops up when opening the document.
I write what I want into the textboxes, and this is in turn put into bookmarks in my document. Sometimes I want to edit some of the userform info, and I call my userform with a keyboard shortcut to update some of the textboxes. I then have some code to populate the textboxes with the bookmarks in the text, so that I don't have to write everything again, just edit what I want.
All of this works just fine when I'm in the template file. The problem occurs when I start a new document with this template. The userform is never populated with the bookmarks from this document, so every time I need to update information in the userform, I have to type in all of information again.
I guess the problem is that the userform is populated with the bookmark-text from my template file. Is this possible to solve in an easy way so that the userform is always populated with the bookmark text from the actual document?
The code I use for populating the userform is this, written in my template.
Private Sub UserForm_Activate()
inndata_ks.Firmanavn.Text = ThisDocument.Bookmarks("firmanavn").Range.Text
inndata_ks.utarbeidet_dato.Text = ThisDocument.Bookmarks("Utarbeidet_dato").Range.Text
inndata_ks.revisjon.Text = ThisDocument.Bookmarks("revisjon").Range.Text
End Sub