How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask GREGMAXEY Your Own Question

GREGMAXEY
GREGMAXEY, Microsoft Word VBA Developer
Category: Microsoft Office
Satisfied Customers: 62
Experience:  I specialize is custom VBA solutions for Microsoft Office Word.
Type Your Microsoft Office Question Here...
GREGMAXEY is online now
A new question is answered every 9 seconds

Ask a Microsoft Word Question I would like to add text to

Customer Question

Ask a Microsoft Word Question
>I would like to add text to a document dependent on a choice i.e, tick box yes or no?

Any idea how this can be done easily
Submitted: 2 years ago.
Category: Microsoft Office
Expert:  GREGMAXEY replied 2 years ago.

There are lots of ways to do this depending on the version of Word and the level of complexity. How easy it is is really up to you. The simpliest is probably a protected form field checkbox with a macro assigned to run on exit.

Sub CBOnExit()
If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
ActiveDocument.Unprotect
ActiveDocument.Range.InsertAfter "Add this text."
ActiveDocument.Protect wdAllowOnlyFormFields, True
End If
End Sub

A more comprehensive method would involve adding the text to a specific targeted range perhaps using a userform.


See: http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm

If you are not familiar with VBA then there probably isn't an "easy" way and you may have to hire someone to design your form for you.

Customer: replied 2 years ago.

I have office 2007 and 2010, so if I add a check box and drop the code in with my proposed text in this section:

 

"Add this text."

 

This will do it when ticked

 

How can I determine where in the document it will go, as in other sections I would like to alternate the text dependent on box ticked (e.g is exclusive or non exclusive) box for exclusive and a box for non exclusive, the text added to the document will depend on box ticked.

 

Thanks

Expert:  GREGMAXEY replied 2 years ago.
If you use Office 2010 then you could use a ContentControl checkbox and the ContentControl OnExit event. This way your form does not have to be protected. Since Word 2007 doesn't have a checkbox content control you could use either a content control dropdown (Yes/No) or you would have to use a protected form and a formfield checkbox.

Yes. If you use a formfield checkbox then replacing "Add this text." with your text would do it.

To fix where the text should go you will have to create a range and write the text to the range or define the text as a document variable and put the variable at the correct place. Information on how to do both is contained in the link I gave you. Writing and testing the actual code would take a fair bit of time.
GREGMAXEY, Microsoft Word VBA Developer
Category: Microsoft Office
Satisfied Customers: 62
Experience: I specialize is custom VBA solutions for Microsoft Office Word.
GREGMAXEY and 5 other Microsoft Office Specialists are ready to help you
Customer: replied 2 years ago.

Hello again, you very kindly helped me yesterday.

I have almost cracked it , I am however having a problem with adding the following text via the macro compile error works fine with a single line but not as a paragraph, any idea?

Sub OnExitCB1B()
Dim oFld As FormFields
Dim oVars As Variables
Dim i As Long
Set oFld = ActiveDocument.FormFields
Set oVars = ActiveDocument.Variables
If oFld("Check9").CheckBox.Value = True Then
oVars("varCheck9Result").Value = _
"Exclusive relationship. Subject to clauses 3.3 and 3.4, the relationship between the parties as contemplated by this Agreement shall be exclusive"
a ISO shall refer all Prospects located in the Territory exclusively to FDGL and procure that FDGL is, in the Territory, the sole and exclusive receipt of all Prospects' referrals by ISO for the Equipment Services and/or services similar to the Equipment Services
b ISO not perform or provide, and shall procure that none of its Affiliates, nor any Entity other than FDGL performs or provides) in the Territory any Equipment Services (and/or all services of the same or similar description as the Equipment Services) for itself or for any of its Affiliates; and
c not promote or endorse the promotion to Prospects of services from a third party which are the same as, similar to or competitive with the Equipment Services (and/or all services of the same or similar description as the Equipment Services) and shall not engage, retain or assist any third party in any such promotion."

Else
oVars("varCheck9Result").Value = _
"Non-exclusive relationship. Subject to clause 3.4, the relationship between the parties as contemplated by this Agreement shall be non-exclusive"
a ISO may promote in or outside the Territory similar services from a competitor of FDGL; and
b nothing in this Agreement shall restrict the ability of either party to act as an agent, partner or joint venturer for or with any other Entity or to act on its own behalf in connection with the provision of any services.

End If
For i = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(i)
If .Type = wdFieldDocVariable Then .Update
End With
Next i
End Sub

Expert:  GREGMAXEY replied 2 years ago.
Sub ScratchMacro()
'A quick macro scratch pad created by Greg Maxey
MsgBox "Paragraphs are created using ""vbcr.""" & vbCr & "This is a new paragraph"
End Sub
Customer: replied 2 years ago.

Don't supose you could add to the macro and highight red, so that I can see how it fits in?

Much appreciated

 

Stephen

Expert:  GREGMAXEY replied 2 years ago.

Here is how one might look:

Sub Test()
MsgBox "Exclusive relationship. Subject to clauses 3.3 and 3.4, " _
& "the relationship between the parties as contemplated by this Agreement shall be exclusive." & vbCr + vbCr _
& "a. ISO shall refer all Prospects located in the Territory exclusively to" _
& " FDGL and procure that FDGL is, in the Territory, the sole and exclusive receipt of all Prospects' referrals" _
& " by ISO for the Equipment Services and/or services similar to the Equipment Services" & vbCr + vbCr _
& "b. ISO not perform or provide, and shall procure that none of its Affiliates, nor any Entity other" _
& " than FDGL performs or provides) in the Territory any Equipment Services (and/or all services of" _
& "the same or similar description as the Equipment Services) for itself or for any of its Affiliates; and" & vbCr + vbCr _
& "c. Not promote or endorse the promotion to Prospects of services from a third party which are the same as," _
& " similar to or competitive with the Equipment Services (and/or all services of the same or similar description as" _
& " the Equipment Services) and shall not engage, retain or assist any third party in any such promotion."
End Sub

Use "_" to break VBA code lines to make them easier to read. User vbCr to create one or more paragraph breaks in the resulting string text.

Customer: replied 2 years ago.
So do you use "_" to break the code up, what do you use to start a new line but not a new paragraph, this will stop the additional numbering in the docment and just put it on another line?
Expert:  GREGMAXEY replied 2 years ago.

Not sure I follow. Try:

Sub ScratchMacro()
ActiveDocument.Range.InsertAfter "Test" & Chr(11) & "test"
End Sub

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • jstinehelfer

    Information Systems Manager

    Satisfied Customers:

    36
    A+ Comptia Certified computer repair
< Last | Next >
  • http://ww2.justanswer.com/uploads/JS/jstinehelfer/2012-6-6_215146_Pictureofme1.64x64.png jstinehelfer's Avatar

    jstinehelfer

    Information Systems Manager

    Satisfied Customers:

    36
    A+ Comptia Certified computer repair
  • http://ww2.justanswer.com/uploads/JA/JasonJames122/2011-12-16_135647_jasonjamesheadshotweb.64x64.jpg JasonJames122's Avatar

    JasonJames122

    Computer Enthusiast

    Satisfied Customers:

    0
    I manage all information systems (network of Windows PC's and servers with Microsoft Office products) for a small business
  • http://ww2.justanswer.com/uploads/JE/jessmagz/2012-6-6_18129_jm.64x64.jpg Jess M.'s Avatar

    Jess M.

    Computer Support Specialist

    Satisfied Customers:

    301
    Computer Software Specialist for more than 10 years
  • http://ww2.justanswer.com/uploads/CH/chutz747/2011-11-6_14231_me.64x64.jpg The-PC-Guy's Avatar

    The-PC-Guy

    Computer Manager

    Satisfied Customers:

    274
    20 years experience providing remote computer support
  • http://ww2.justanswer.com/uploads/SP/spherrod/2012-6-6_174244_1000852.64x64.JPG Steve Herrod's Avatar

    Steve Herrod

    Computer Support Specialist

    Satisfied Customers:

    125
    Trained in Microsoft Office from 2000 through to latest version 2010.
  • http://ww2.justanswer.com/uploads/SE/Seashore2011/2011-12-6_33418_111205223015.64x64.jpg Chris L.'s Avatar

    Chris L.

    Support Specialist

    Satisfied Customers:

    124
    Certified Expert with over 10 years experience.
  • http://ww2.justanswer.com/uploads/KR/krkljatorm/2012-6-24_153417_ITMiro.64x64.jpg IT Miro's Avatar

    IT Miro

    Computer Scientist

    Satisfied Customers:

    97
    Bachelor's Degree in Information Technology, Microsoft Certified Professional