Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 05-09-2017, 06:35 PM
gsandy gsandy is offline Select Text after Bookmark Windows 7 64bit Select Text after Bookmark Office 2013
Novice
Select Text after Bookmark
 
Join Date: Mar 2017
Location: New Zealand
Posts: 10
gsandy is on a distinguished road
Default

I have got the code working with 4 bookmarks. The 4th bookmark (bmRe) is working except that I want to add the contents of a userform textbox (txtProject). This has been commented out because the code won’t run if left in. The error says that that the variable is not defined. If I add txtProject to the Call code brackets then I get a compile error. Any help would be appreciated. (I am unsure if I should put this on a new thread?).

Code:
  Sub UpdateBookmark(bmContact As String, bmCompany As String, bmAddress As String, bmRe As String, StrTxtContact As String, StrTxtCompany As String, StrTxtAddress As String)
   
      Dim BkMkContact As Range
      Dim BkMkCompany As Range
      Dim BkMkAddress As Range
      Dim BkMkRe As Range
   
      With ActiveDocument
          'Contact
          If .Bookmarks.Exists(bmContact) Then
              Set BkMkContact = .Bookmarks(bmContact).Range
              BkMkContact.Text = StrTxtContact
              .Bookmarks.Add bmContact, BkMkContact
          End If
          'Company
          If .Bookmarks.Exists(bmCompany) Then
              Set BkMkCompany = .Bookmarks(bmCompany).Range
              BkMkCompany.Text = StrTxtCompany
              .Bookmarks.Add bmCompany, BkMkCompany
          End If
          'Address
          If .Bookmarks.Exists(bmAddress) Then
              Set BkMkAddress = .Bookmarks(bmAddress).Range
              BkMkAddress.Text = StrTxtAddress
              .Bookmarks.Add bmAddress, BkMkAddress
          End If
          'Re
          If .Bookmarks.Exists(bmRe) Then
              Set BkMkRe = .Bookmarks(bmRe).Range
              BkMkRe.Text = "Re: "    '& txtProject
              .Bookmarks.Add bmRe, BkMkRe
          End If
   
          .Fields.Update
      End With
   
      Set BkMkContact = Nothing
      Set BkMkCompany = Nothing
      Set BkMkAddress = Nothing
      Set BkMkRe = Nothing
   
  End Sub
Called with:
Code:
  Private Sub CommandButton1_Click()
   
      Call UpdateBookmark("bmContact", "bmCompany", "bmAddress", "bmRe", txtContact, txtCompany, txtAddress)
   
  End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a bookmark to text within a header jroger05 Word VBA 3 07-14-2016 02:28 PM
VBA Search Table for Text/Select Text/Insert Hyperlink sldrellich Word VBA 3 03-24-2015 01:09 PM
Microsoft Word macro to find text, select all text between brackets, and delete helal1990 Word VBA 4 02-05-2015 03:52 PM
Repeating Bookmark Text BECKTHOMO Word 1 03-27-2012 08:34 PM
Select Text after Bookmark Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:57 AM.


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