Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 11-20-2012, 10:53 AM
gmaxey gmaxey is offline Creating a plain text content control for every instance of a word or phrase Windows 7 32bit Creating a plain text content control for every instance of a word or phrase Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Couple of other things you might consider.

1) Use calls to functions to do standard things like validate a unique title:

HTML Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim strTitle As String
strTitle = "Name"
'Is this a unique titled?  Check with function
If fcn_IsTitleUnique(strTitle) Then
  Debug.Print "Yep it is."
Else
  Debug.Print "Nope its not."
End If
End Sub
Function fcn_IsTitleUnique(ByRef strTitlePassed As String) As Boolean
Dim oCol As New Collection
Dim oCC As ContentControl
fcn_IsTitleUnique = True
For Each oCC In ActiveDocument.ContentControls
  oCol.Add oCC.Title, oCC.Title
Next oCC
  On Error Resume Next
  oCol.Add strTitlePassed, strTitlePassed
  If Err.Number = 0 Then fcn_IsTitleUnique = True
  On Error GoTo 0
lbl_Exit:
  Exit Function
End Function
2) You can simplify InputBox code using StrPtr. This lets you determine between user pressing "Cancel" or not making an entry:

HTML Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim strDemo As String
Dim bVillageIdiotNeedsHelp As Boolean
bVillageIdiotNeedsHelp = False
Do
  If Not bVillageIdiotNeedsHelp Then
    strDemo = InputBox("Enter your name")
    bVillageIdiotNeedsHelp = True
  Else
    strDemo = InputBox("You have an name even if it is Village Idiot." & vbCr + vbCr _
                      & "Please enter your name!")
  End If
  'User cancels.
  If StrPtr(strDemo) = 0 Then GoTo lbl_Exit
Loop Until strDemo <> ""
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 

Tags
content control, find & replace, xml



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a plain text content control for every instance of a word or phrase Rich text/Plain text Content Controls in Template michael.fisher5 Word 9 11-19-2014 06:36 AM
Creating a plain text content control for every instance of a word or phrase How do you set rich text in a content control Testor Word VBA 4 07-08-2012 07:55 AM
Word2010 check boxes and plain text content control boxes in same table fcsungard Word 5 06-01-2012 01:16 AM
Creating a plain text content control for every instance of a word or phrase Rich Text Content Control - Allow User Formatting keithacochrane Word 1 05-28-2012 05:06 PM
Templates: automatic text generation from Rich Text content control Chickenmunga Word 0 10-01-2008 11:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:09 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