Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-04-2013, 08:00 PM
macropod's Avatar
macropod macropod is offline VBA to input / clear text from a Bookmark Windows 7 32bit VBA to input / clear text from a Bookmark Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

A couple of things:
1. Instead of having a plethora of bookmarks for each replicated item, use just one and insert cross-references to it.
2. To correctly update the bookmarks use code like:
Code:
Private Sub btnInputData_Click()
Application.ScreenUpdating = False
Dim wdDoc As Document
Set wdDoc = ActiveDocument
Call UpdateBookmark(wdDoc, "bmSite", Me.txtSite.Value)
Call UpdateBookmark(wdDoc, "bmclient", Me.txtClient.Value)
Call UpdateBookmark(wdDoc, "bmContactNo", Me.txtContactNumber.Value)
Call UpdateBookmark(wdDoc, "bmProjectManager", Me.txtProjectManager.Value)
Call UpdateBookmark(wdDoc, "bmSupervisor", Me.txtSupervisor.Value)
Call UpdateBookmark(wdDoc, "bmProjectNo", Me.txtProjectNumber.Value)
Call UpdateBookmark(wdDoc, "bmStartDate", Me.DTPicker1.Value)
Call UpdateBookmark(wdDoc, "bmEndDate", Me.DTPicker2.Value)
'
'The rest of your code, from 'Print Sections' onwards, goes here
'
wdDoc.Fields.Update
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
'
Sub UpdateBookmark(wdDoc As Document, BmkNm As String, NewTxt As String)
Dim BmkRng As Range
With wdDoc
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    BmkRng.Text = NewTxt
    .Bookmarks.Add BmkNm, BmkRng
  End If
End With
Set BmkRng = Nothing
End Sub

__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to input / clear text from a Bookmark Replacing text with user input.?.?.? brad1977 Word 3 11-20-2012 10:20 AM
VBA to input / clear text from a Bookmark Open header to insert text into bookmark Amapola188 Word VBA 3 07-12-2012 05:16 PM
Repeating Bookmark Text BECKTHOMO Word 1 03-27-2012 08:34 PM
VBA to input / clear text from a Bookmark Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM
VBA to input / clear text from a Bookmark delete all bookmark text hklein Word VBA 4 08-10-2011 04:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft