Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-04-2013, 06:42 PM
micko1 micko1 is offline VBA to input / clear text from a Bookmark Windows 7 64bit VBA to input / clear text from a Bookmark Office 2010 32bit
Novice
VBA to input / clear text from a Bookmark
 
Join Date: Nov 2013
Posts: 2
micko1 is on a distinguished road
Default VBA to input / clear text from a Bookmark

Extreme Newbie. I have a word doc that is broken up into sections. The first page of each section has like fields eg "Site", "Client", "Project Manager", "Start Date" and so on. I have done some work with Excel and Access but am new to Word. I have created a user form that allows the user to enter the relevant data once, press a button and then auto populate the like fields on each section. The user is then able to tick a check box to select what section they want to print. The issue I have is once the user completes the fields and then presses the button to put the data into the relevant fields and the form prints.I am not able to clear the data in the doc for another entry to occur.
Any and all help would be greatly appreciated.


Code:
Private Sub btnInputData_Click()
Dim bmks As Bookmarks
Dim bmRange As Range
'Pass the userform values to the document's bookmarks.
Set bmks = ActiveDocument.Bookmarks
Set bmRange = ActiveDocument.Bookmarks("bmSite").Range
bmRange.Text = Me.txtSite.Value
Set bmRange = ActiveDocument.Bookmarks("bmSite1").Range
bmRange.Text = Me.txtSite.Value
Set bmRange = ActiveDocument.Bookmarks("bmSite2").Range
bmRange.Text = Me.txtSite.Value
Set bmRange = ActiveDocument.Bookmarks("bmSite3").Range
bmRange.Text = Me.txtSite.Value
Set bmRange = ActiveDocument.Bookmarks("bmSite4").Range
bmRange.Text = Me.txtSite.Value
Set bmRange = ActiveDocument.Bookmarks("bmSite5").Range
bmRange.Text = Me.txtSite.Value
Set bmRange = ActiveDocument.Bookmarks("bmSite6").Range
bmRange.Text = Me.txtSite.Value
'Set Client
Set bmRange = ActiveDocument.Bookmarks("bmclient").Range
bmRange.Text = Me.txtClient.Value
Set bmRange = ActiveDocument.Bookmarks("bmclient1").Range
bmRange.Text = Me.txtClient.Value
Set bmRange = ActiveDocument.Bookmarks("bmclient2").Range
bmRange.Text = Me.txtClient.Value
Set bmRange = ActiveDocument.Bookmarks("bmclient3").Range
bmRange.Text = Me.txtClient.Value
Set bmRange = ActiveDocument.Bookmarks("bmclient4").Range
bmRange.Text = Me.txtClient.Value
Set bmRange = ActiveDocument.Bookmarks("bmclient5").Range
bmRange.Text = Me.txtClient.Value
Set bmRange = ActiveDocument.Bookmarks("bmclient6").Range
bmRange.Text = Me.txtClient.Value
'Set Contact Number
Set bmRange = ActiveDocument.Bookmarks("bmContactNo").Range
bmRange.Text = Me.txtContactNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmContactNo1").Range
bmRange.Text = Me.txtContactNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmContactNo2").Range
bmRange.Text = Me.txtContactNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmContactNo3").Range
bmRange.Text = Me.txtContactNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmContactNo4").Range
bmRange.Text = Me.txtContactNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmContactNo5").Range
bmRange.Text = Me.txtContactNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmContactNo6").Range
bmRange.Text = Me.txtContactNumber.Value
'Set Project Manager
Set bmRange = ActiveDocument.Bookmarks("bmProjectManager").Range
bmRange.Text = Me.txtProjectManager.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectManager1").Range
bmRange.Text = Me.txtProjectManager.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectManager2").Range
bmRange.Text = Me.txtProjectManager.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectManager3").Range
bmRange.Text = Me.txtProjectManager.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectManager4").Range
bmRange.Text = Me.txtProjectManager.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectManager5").Range
bmRange.Text = Me.txtProjectManager.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectManager6").Range
bmRange.Text = Me.txtProjectManager.Value
'Set Supervisor
Set bmRange = ActiveDocument.Bookmarks("bmSupervisor").Range
bmRange.Text = Me.txtSupervisor.Value
Set bmRange = ActiveDocument.Bookmarks("bmSupervisor1").Range
bmRange.Text = Me.txtSupervisor.Value
Set bmRange = ActiveDocument.Bookmarks("bmSupervisor2").Range
bmRange.Text = Me.txtSupervisor.Value
Set bmRange = ActiveDocument.Bookmarks("bmSupervisor3").Range
bmRange.Text = Me.txtSupervisor.Value
Set bmRange = ActiveDocument.Bookmarks("bmSupervisor4").Range
bmRange.Text = Me.txtSupervisor.Value
Set bmRange = ActiveDocument.Bookmarks("bmSupervisor5").Range
bmRange.Text = Me.txtSupervisor.Value
Set bmRange = ActiveDocument.Bookmarks("bmSupervisor6").Range
bmRange.Text = Me.txtSupervisor.Value
'Set ProjectNumber
Set bmRange = ActiveDocument.Bookmarks("bmProjectNo").Range
bmRange.Text = Me.txtProjectNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectNo1").Range
bmRange.Text = Me.txtProjectNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectNo2").Range
bmRange.Text = Me.txtProjectNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectNo3").Range
bmRange.Text = Me.txtProjectNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectNo4").Range
bmRange.Text = Me.txtProjectNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectNo5").Range
bmRange.Text = Me.txtProjectNumber.Value
Set bmRange = ActiveDocument.Bookmarks("bmProjectNo6").Range
bmRange.Text = Me.txtProjectNumber.Value
'Set Start Date and end Date
Set bmRange = ActiveDocument.Bookmarks("bmStartDate").Range
bmRange.Text = Me.DTPicker1.Value
Set bmRange = ActiveDocument.Bookmarks("bmEndDate").Range
bmRange.Text = Me.DTPicker2.Value
Set bmRange = ActiveDocument.Bookmarks("bmStartDate1").Range
bmRange.Text = Me.DTPicker1.Value
Set bmRange = ActiveDocument.Bookmarks("bmEndDate1").Range
bmRange.Text = Me.DTPicker2.Value
Set bmRange = ActiveDocument.Bookmarks("bmStartDate2").Range
bmRange.Text = Me.DTPicker1.Value
Set bmRange = ActiveDocument.Bookmarks("bmEndDate2").Range
bmRange.Text = Me.DTPicker2.Value
Set bmRange = ActiveDocument.Bookmarks("bmStartDate3").Range
bmRange.Text = Me.DTPicker1.Value
Set bmRange = ActiveDocument.Bookmarks("bmEndDate3").Range
bmRange.Text = Me.DTPicker2.Value
Set bmRange = ActiveDocument.Bookmarks("bmStartDate4").Range
bmRange.Text = Me.DTPicker1.Value
Set bmRange = ActiveDocument.Bookmarks("bmEndDate4").Range
bmRange.Text = Me.DTPicker2.Value
Set bmRange = ActiveDocument.Bookmarks("bmStartDate5").Range
bmRange.Text = Me.DTPicker1.Value
Set bmRange = ActiveDocument.Bookmarks("bmEndDate5").Range
bmRange.Text = Me.DTPicker2.Value
Set bmRange = ActiveDocument.Bookmarks("bmStartDate6").Range
bmRange.Text = Me.DTPicker1.Value
Set bmRange = ActiveDocument.Bookmarks("bmEndDate6").Range
bmRange.Text = Me.DTPicker2.Value
 
'Print Sections
If cbLocations.Value = "True" Then
Dialogs(wdDialogFilePrint).Display
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
       wdPrintDocumentWithMarkup, Copies:=1, Pages:="1,2-14", PageType:= _
       wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
        PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0
ElseIf cbPitPipe.Value = "True" Then
Dialogs(wdDialogFilePrint).Display
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
      wdPrintDocumentWithMarkup, Copies:=1, Pages:="1,15-31", PageType:= _
      wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
      PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
      PrintZoomPaperHeight:=0
      
ElseIf cbACM.Value = "True" Then
Dialogs(wdDialogFilePrint).Display
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
      wdPrintDocumentWithMarkup, Copies:=1, Pages:="1,32-62", PageType:= _
      wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
      PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
      PrintZoomPaperHeight:=0
      
ElseIf cbHaul.Value = "True" Then
Dialogs(wdDialogFilePrint).Display
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
      wdPrintDocumentWithMarkup, Copies:=1, Pages:="1,63-73", PageType:= _
      wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
      PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
      PrintZoomPaperHeight:=0
      
ElseIf cbDrill.Value = "True" Then
Dialogs(wdDialogFilePrint).Display
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
      wdPrintDocumentWithMarkup, Copies:=1, Pages:="1,74-89", PageType:= _
      wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
      PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
      PrintZoomPaperHeight:=0
      
ElseIf cbAerial.Value = "True" Then
Dialogs(wdDialogFilePrint).Display
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
      wdPrintDocumentWithMarkup, Copies:=1, Pages:="1,90-100", PageType:= _
      wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
      PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
      PrintZoomPaperHeight:=0
ElseIf cbJointing.Value = "True" Then
Dialogs(wdDialogFilePrint).Display
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
      wdPrintDocumentWithMarkup, Copies:=1, Pages:="1,101-113", PageType:= _
      wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
      PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
      PrintZoomPaperHeight:=0
Else
Exit Sub
End If
 
End Sub
Reply With Quote
 

Thread Tools
Display Modes


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 03:19 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