|
-
Mar 27th, 2009, 05:40 AM
#1
Thread Starter
Lively Member
[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
-
Mar 27th, 2009, 05:59 AM
#2
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 27th, 2009, 06:30 AM
#3
Thread Starter
Lively Member
Re: Word VBA Bookmarks Galore!
Ah Brilliant! I knew it would be something simple, thanks! I'll give it a go.
 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!
Last edited by Kubull; Mar 27th, 2009 at 06:59 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|