Hi. I´m really new with VBA but am trying to edit my word-document.
It is a word-document where i edit different bookmarks spread thoughout the text with a userform that pops up when opening the document.
I use this code (and there are 14 more bookmarks i´m not showing here):
Privat Sub Generera_Click() Dim Inskrivning_fastighetsbeteckning As Range Set Inskrivning_fastighetsbeteckning = ThisDocument.Bookmarks("Inskrivning_fastighetsbeteckning").Range Set Inskrivning_fastighetsbeteckning1 = ThisDocument.Bookmarks("Inskrivning_fastighetsbeteckning1").Range Set Inskrivning_fastighetsbeteckning2 = ThisDocument.Bookmarks("Inskrivning_fastighetsbeteckning2").Range Set Inskrivning_fastighetsbeteckning3 = ThisDocument.Bookmarks("Inskrivning_fastighetsbeteckning3").Range Inskrivning_fastighetsbeteckning.Text = Me.TextBox1.Value Inskrivning_fastighetsbeteckning1.Text = Me.TextBox1.Value Inskrivning_fastighetsbeteckning2.Text = Me.TextBox1.Value Inskrivning_fastighetsbeteckning3.Text = Me.TextBox1.Value Me.Repaint UserForm1.Hide End Sub
My issue is that my code deletes the bookmarks after writing to them. And it is also very laborious to enter the bookmarks throughout the text (some repeat 25 times) to begin with.
I first wanted to create code that recreated the bookmarks over the new textvalues but then I still have the the problem with repeating bookmarks up to 25 times (name1, name2 etc) in the first place.
I really want to use Custom document properties instead but I don´t know how to change my code to change the values in the Custom document properties. PS. I have created the custom document properties in the document and they work when editing them manually.
If I could use the userform to change the values then it would be sooooo much more helpful for me, my team and my customers. The userform could change from a onetime thing to something used for editing the document in all future revisions.
These are the names of my customdocumentproperties:
"Inskrivning_Fastighetsbeteckning"
"Inskrivning_Företagsnamn"
"Inskrivning_Verksamhetsnamn"
"Inskrivning_Gatuadress"
"Inskrivning_Postadress"
"Inskrivning_Organisationsnummer"
"Inskrivning_Pärms_placering"
"Inskrivning_Återsamlingsplats"
"Inskrivning_Fastighetsägare"
"Inskrivning_Fastighetsägare_organisationsnummer"
"Inskrivning_Teknikernamn"
"Inskrivning_Teknikergatuadress"
"Inskrivning_Teknikerpostadress"
"Inskrivning_Tekniker_epost"
"Inskrivning_Tekniker_telefon"
My textboxes are named from TextBox1 to TextBox15 and reflect the order of the above documentproperties.
How do i go about achieving this?
I have also other questions regarding my userform but everyting depends on getting the userform to change the values of existing customdocumentproperties.
There are also lot of checkboxes that delete other bookmarks also in this code (i didn´t show them in the first code cause they are not the issue for me, they work but i don´t really know if they are efficient):
Like i said to start with, I am really new at this and am basically learning by doing for now.Dim Name_Name As Range Set Name_Name = ThisDocument.Bookmarks("Name_Name").Range If UserForm1.CB_Name.Value = False Then Name_Name.Delete End If