PDA

View Full Version : Solved: Capitalise First letter of Sentences



fosterp
04-10-2008, 01:19 AM
I have a Document where the word "in" appears in both Capital and small letters.
The problem is, there are a lot of instances where ?in? appears in capitals in the middle of the sentence where I want it to be small letters and ?in? appears in
small letters at the beginning of the sentence when I want it to be in Capital letters.

I believe that there is VBA code that could solve this problem.
Please could someone help me with this.

fumei
04-10-2008, 12:07 PM
A confusing post.

Please post an example.

fosterp
04-11-2008, 01:07 AM
e.g. If you have lots of instances of a sentence like the one below:

in the cells shown type in the information below:

Using search and replace, would result in all instances of "in" appearing as "In"

whereas I want the word "in" to be Capitalised at the beginning of the sentence only.

I hope this makes sense ( I am using Excel 2003 ).

chandansify
04-11-2008, 02:06 AM
I have a Document where the word "in" appears in both Capital and small letters.
The problem is, there are a lot of instances where ?in? appears in capitals in the middle of the sentence where I want it to be small letters and ?in? appears in
small letters at the beginning of the sentence when I want it to be in Capital letters.

I believe that there is VBA code that could solve this problem.
Please could someone help me with this.


Try this if it works for you.



Sub CorrectFormat()

Dim bChange As Boolean
Dim sText As String
Selection.HomeKey wdStory
While Selection.Find.Execute("IN", False, True) = True
ActiveDocument.Bookmarks.Add "tmpBM", Selection
Selection.MoveLeft
Selection.MoveLeft wdCharacter, 1, wdExtend
'Checking start of sentence by paragraph mark
If Asc(Selection.Text) = 13 Then
bChange = True
Else
bChange = False
End If
ActiveDocument.Bookmarks.Item("tmpBM").Select
If bChange = True Then
Selection.Text = StrConv("in", vbProperCase)
Else
Selection.Text = StrConv("in", vbLowerCase)
End If
Wend

If ActiveDocument.Bookmarks.Exists("tmpBM") Then
ActiveDocument.Bookmarks.Item("tmpBM").Delete
End If


End Sub

fosterp
04-11-2008, 03:38 AM
Thx for that, it did work.

BTW, Where is the Thread Tools dropdown at the top of the thread?
I want to Mark my thread solved

fumei
04-11-2008, 10:07 AM
I am still not following. If you have (sample):

In the first place in the In the cells shown type In the information below:

In the first place in the In the cells shown type In the information below:

I bolded the instances of In that are inside the sentence (i.e. NOT at the start).

Now:

Dim r As Range
Set r = ActiveDocument.Range
With r
.Case = wdLowerCase
.Case = wdTitleSentence
End With

will first make everything lowercase, then TitleSentence. Result?

In the first place in the in the cells shown type in the information below:

In the first place in the in the cells shown type in the information below:


The inside In become lowercase, and the sentence has a capital for the first letter (TitleSentence).

I do not understand the need to use Selection to do a find, replace, nor do I understand the use of creating bookmarks, and testing them, and deleting them etc. etc.

It seems way over the top. However, i could be not understanding what the problem actually is.

But if you simply want to make sure there are no capitalized words inside a sentence, then...just do that.

I also would very much like to know HOW you have capitalized In (within a sentence) in the first place.

fosterp
04-11-2008, 10:27 AM
Thx. your solution worked perfect.