[RESOLVED] Word VBA Bookmarks Galore!
Hi,
I'm developing a template thats updated every financial year, it contains the same year date in it about a 100 times "2008/09" depending on which year its about. I've managed to automate it via a VBA form but the sheer number of bookmarks makes it a up hill task,
To name but a few: (I had to shorten the below list due to the scale of them)
Code:
Private Sub cmd_ok_Click()
'Entering financial year date into Heading 1
ActiveDocument.Bookmarks("TitleDate1").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("TitleDate2").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("TitleDate3").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("TitleDate4").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("TitleDate5").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("TitleDate6").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("TitleDate7").Select
Selection.Text = (frmendyear.txtdate.Text)
'Entering financial year date into standard text
ActiveDocument.Bookmarks("textdate1").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("textdate2").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("textdate3").Select
Selection.Text = (frmendyear.txtdate.Text)
ActiveDocument.Bookmarks("textdate4").Select
Selection.Text = (frmendyear.txtdate.Text)
'Entering in 'To' Financial date
ActiveDocument.Bookmarks("todate1").Select
Selection.Text = (frmendyear.txtto.Text)
ActiveDocument.Bookmarks("todate2").Select
Selection.Text = (frmendyear.txtto.Text)
ActiveDocument.Bookmarks("todate3").Select
Selection.Text = (frmendyear.txtto.Text)
ActiveDocument.Bookmarks("todate4").Select
Selection.Text = (frmendyear.txtto.Text)
Would anyone know a code that would shorten the above, or is this the only way?
Cheers
Re: Word VBA Bookmarks Galore!
Something like this?
Code:
Private Sub cmd_ok_Click()
Dim I As Long, J As Long, K As Long
For I = 1 To 7
'Entering financial year date into Heading 1
ActiveDocument.Bookmarks("TitleDate" & I).Select
Selection.Text = (frmendyear.txtdate.Text)
DoEvents
Next I
For J = 1 To 4
'Entering financial year date into standard text
ActiveDocument.Bookmarks("textdate" & J).Select
Selection.Text = (frmendyear.txtdate.Text)
DoEvents
Next J
For K = 1 To 4
'Entering in 'To' Financial date
ActiveDocument.Bookmarks("todate" & K).Select
Selection.Text = (frmendyear.txtto.Text)
DoEvents
Next K
End Sub
Re: Word VBA Bookmarks Galore!
Ah Brilliant! I knew it would be something simple, thanks! I'll give it a go.
Quote:
Originally Posted by
koolsid
Something like this?
Code:
Private Sub cmd_ok_Click()
Dim I As Long, J As Long, K As Long
For I = 1 To 7
'Entering financial year date into Heading 1
ActiveDocument.Bookmarks("TitleDate" & I).Select
Selection.Text = (frmendyear.txtdate.Text)
DoEvents
Next I
For J = 1 To 4
'Entering financial year date into standard text
ActiveDocument.Bookmarks("textdate" & J).Select
Selection.Text = (frmendyear.txtdate.Text)
DoEvents
Next J
For K = 1 To 4
'Entering in 'To' Financial date
ActiveDocument.Bookmarks("todate" & K).Select
Selection.Text = (frmendyear.txtto.Text)
DoEvents
Next K
End Sub
*Edit
Works like a charm, thanks again!