Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-27-2015, 01:52 PM
ksigcajun ksigcajun is offline Bolding in script Windows 7 64bit Bolding in script Office 2010 64bit
Advanced Beginner
Bolding in script
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default Bolding in script

I'm sure this has been covered previously, so I do apologize. I did search, but couldnt find what I was looking for.



I've built a script that will place text in a form when an option button is chosen. I want to have the numbers for each paragraph bolded and not the text.

I know how to bold the entire paragraph, but not just some.

Ex: Currently
10.2.3 - By clicking on the form name, form description or form settings link from the New Form or Edit Form screen, you will activate the form settings interface. The form settings interface consists of three tabs. Each tab consists of options and settings for the form.

10.2.4 - You may select to either use a text based button or an image button. If you would like to use text for a button simply select Text and type in what you would like to appear as the button text. To use an image, select Image and enter the full path to the image you would like to use for the submit button.

Need it to be
10.2.3 - By clicking on the form name, form description or form settings link from the New Form or Edit Form screen, you will activate the form settings interface. The form settings interface consists of three tabs. Each tab consists of options and settings for the form.

10.2.4 - You may select to either use a text based button or an image button. If you would like to use text for a button simply select Text and type in what you would like to appear as the button text. To use an image, select Image and enter the full path to the image you would like to use for the submit button.

PHP Code:
Private Sub OptionButton1_Click()
If 
Me.OptionButton1.Value True Then
   Set oRng 
ActiveDocument.Bookmarks("BM2").Range
     oRng
.Text "10.2.3 - By clicking on the form name, form description or form settings link from the New Form or Edit Form screen, you will activate the form settings interface. The form settings interface consists of three tabs. Each tab consists of options and settings for the form." vbCr _
"10.2.4 - You may select to either use a text based button or an image button. If you would like to use text for a button simply select Text and type in what you would like to appear as the button text. To use an image, select Image and enter the full path to the image you would like to use for the submit button."vbCr _
ActiveDocument
.Bookmarks.Add "BM2"oRng
End 
If
End Sub 
Reply With Quote
  #2  
Old 01-27-2015, 03:47 PM
macropod's Avatar
macropod macropod is offline Bolding in script Windows 7 64bit Bolding in script Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,446
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

If these are multi-level list #s inserted by Word, you can't reference them that way - you need to change the numbering format. If they are not multi-level list #s inserted by Word, they probably should be changed to them (makes document maintenance much easier), but you can change all of them in one go via a wildcard Find/Replace, where:
Find = <[0-9]@.[0-9]@.[0-9]@>
Replace = ^&
and setting the replacement font format to Bold.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 01-28-2015, 07:54 AM
ksigcajun ksigcajun is offline Bolding in script Windows 7 64bit Bolding in script Office 2010 64bit
Advanced Beginner
Bolding in script
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
If these are multi-level list #s inserted by Word, you can't reference them that way - you need to change the numbering format. If they are not multi-level list #s inserted by Word, they probably should be changed to them (makes document maintenance much easier), but you can change all of them in one go via a wildcard Find/Replace, where:
Find = <[0-9]@.[0-9]@.[0-9]@>
Replace = ^&
and setting the replacement font format to Bold.
These is not a multi-level list inserted by Word. This is a numbering system I've placed in the form.

How would I go about adding a find and replace in my script?
Reply With Quote
  #4  
Old 01-28-2015, 02:29 PM
macropod's Avatar
macropod macropod is offline Bolding in script Windows 7 64bit Bolding in script Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,446
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

You could use the macro recorder to record such a Find/Replace, then add the relevant portions of the recorded code to your existing sub. There are also plenty of posts in this forum showing the use of Find/Replace in macros.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 01-28-2015, 02:43 PM
ksigcajun ksigcajun is offline Bolding in script Windows 7 64bit Bolding in script Office 2010 64bit
Advanced Beginner
Bolding in script
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
You could use the macro recorder to record such a Find/Replace, then add the relevant portions of the recorded code to your existing sub. There are also plenty of posts in this forum showing the use of Find/Replace in macros.
Thanks! Ill do a quick search on here.
Reply With Quote
  #6  
Old 01-28-2015, 07:11 PM
Guessed's Avatar
Guessed Guessed is offline Bolding in script Windows 7 32bit Bolding in script Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,708
Guessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of light
Default

You don't need to bother with a search and replace if you make use of the selection.expand method. For instance, you could add the following in front of the End If line
Code:
  Dim oPar As Paragraph
  For Each oPar In oRng.Paragraphs
    oPar.Range.Select
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Extend " "
    Selection.Font.Bold = True
  Next oPar
This would be much slicker if you could use the range directly and didn't need the selection object but I don't think extend works for ranges.
Reply With Quote
  #7  
Old 01-28-2015, 07:20 PM
macropod's Avatar
macropod macropod is offline Bolding in script Windows 7 64bit Bolding in script Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,446
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Quote:
Originally Posted by Guessed View Post
This would be much slicker if you could use the range directly and didn't need the selection object but I don't think extend works for ranges.
how about:
Code:
Dim oPar As Paragraph
  For Each oPar In oRng.Paragraphs
    With oPar.Range
      .Collapse Direction:=wdCollapseStart
      .MoveEndUntil " ", wdForward
      .Font.Bold = True
    End With
  Next oPar
Much more efficient than working with selections, too.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #8  
Old 01-28-2015, 07:58 PM
Guessed's Avatar
Guessed Guessed is offline Bolding in script Windows 7 32bit Bolding in script Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,708
Guessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of light
Default

Nice one Paul. That is what I was looking for before I reverted to Selections.
Reply With Quote
  #9  
Old 02-19-2015, 06:23 AM
pentagram_31 pentagram_31 is offline Bolding in script Windows 7 32bit Bolding in script Office 2013
Novice
 
Join Date: Feb 2015
Posts: 13
pentagram_31 is on a distinguished road
Default

I have a similar question:
I have a lot of test questions to edit, an example of which is:


1. Everyday items, such as umbrellas or shoes, can become ........ if they were once owned by a celebrity. The umbrellas used by 'The Beatles' in their film 'Help' are worth a small fortune now.
A) useful B) practical C) countless D) infinite E) valuable


What I need to do is that I need to edit all of the questions so that they become like the example above: the question is bold and the options are not. I wish there were a macro to find "A)" and then automatically make the line bold. I hope I was able to make it clear.
Reply With Quote
  #10  
Old 02-19-2015, 09:54 PM
Guessed's Avatar
Guessed Guessed is offline Bolding in script Windows 7 32bit Bolding in script Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,708
Guessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of light
Default

Perhaps a macro like this would work if the styles were formatted correctly.
Code:
Dim oPar As Paragraph
  For Each oPar In ActiveDocument.Paragraphs
    If Left(oPar.Range.Text,2) = "A)" then
      oPar.Range.Style = "Normal Indent"
    Else
      oPar.Range.Style = "Normal"
    End if
  Next
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #11  
Old 02-23-2015, 08:29 AM
pentagram_31 pentagram_31 is offline Bolding in script Windows 7 32bit Bolding in script Office 2013
Novice
 
Join Date: Feb 2015
Posts: 13
pentagram_31 is on a distinguished road
Default Thanks

Thanks for your reply. In the meantime, I tried and found sth like this and it works like charm for me so far:
Code:
Sub Makro5()

Selection.Find.ClearFormatting
With Selection.Find
   .Text = "A)"
   .Forward = True
   '.Wrap = wdFindContinue
   .Format = False
   .MatchCase = True
   .MatchWholeWord = True
   .MatchWildcards = False
   .MatchSoundsLike = False
   .MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found = True Then
    
    Selection.MoveUp Unit:=wdParagraph, Count:=3, Extend:=wdExtend
    Selection.Font.Bold = wdToggle
    Selection.MoveDown Unit:=wdParagraph, Count:=2
End If
End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with VBA script nsyrax Word VBA 1 01-18-2014 03:38 AM
Bolding in script Outlook Script Help TheInfinetGroup Outlook 1 03-02-2013 07:43 AM
Add Shared Calendar using script Antros Outlook 0 03-15-2012 01:01 PM
Bolding in script Script Doesn't works on other machine ravininave Word 1 01-05-2011 01:45 PM
[ask] about VB Script + Ms. Project anak_baru Project 2 03-10-2009 01:42 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 10:01 AM.


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