Pages in topic:   < [1 2]
Macro to Capitalize the first occurring alphabet in a MS Word Table
Thread poster: Jigar Kantharia
Shouguang Cao
Shouguang Cao  Identity Verified
China
Local time: 05:41
English to Chinese
+ ...
This one is fast Jul 24, 2017

This one is much shorter and much faster. Thank you Ben for the suggestion


Sub captalize()


' captalize the first letter of each line and uncaptitalize the rest
Application.ScreenUpdating = False



Selection.WholeStory
Selection.Range.Case = wdNextCase
Selection.Range.Case = wdNextCase

para_count = ActiveDocument.Paragraphs.Count
For i = 1 To para_count
para_length = ActiveDocu
... See more
This one is much shorter and much faster. Thank you Ben for the suggestion


Sub captalize()


' captalize the first letter of each line and uncaptitalize the rest
Application.ScreenUpdating = False



Selection.WholeStory
Selection.Range.Case = wdNextCase
Selection.Range.Case = wdNextCase

para_count = ActiveDocument.Paragraphs.Count
For i = 1 To para_count
para_length = ActiveDocument.Paragraphs(i).Range.Characters.Count

For j = 1 To para_length
Set current_char = ActiveDocument.Paragraphs(i).Range.Characters.Item(j)

If IsLowerChar(current_char.Text) Then
current_char.Select
Selection.TypeText (UCase(current_char.Text))
Exit For
End If

Next j
Next i
End Sub


Function IsLowerChar(CHR As String) As Boolean
'by Rolf Keller
CHR = Left(CHR, 1)
X1 = (LCase(CHR) = CHR)
X2 = (UCase(CHR) = CHR)
IsLowerChar = X1 And (Not X2)
End Function





[Edited at 2017-07-24 18:03 GMT]

[Edited at 2017-07-25 07:59 GMT]
Collapse


 
Rolf Keller
Rolf Keller
Germany
Local time: 22:41
English to German
Ok, my 2 cents Jul 26, 2017

Sub captalize()

' captalize the first letter of each line and uncaptitalize the rest

Selection.WholeStory
Selection.Range.Case = wdLowerCase

Set paras = ActiveDocument.Paragraphs
para_count = paras.Count

For i = 1 To para_count

Set first_char = paras(i).Range.Characters.Item(1)
If IsLowerChar(first_char.Text) Then
first_char.Select
Selection.TypeText (UCase(first_char.Text))
End If

N
... See more
Sub captalize()

' captalize the first letter of each line and uncaptitalize the rest

Selection.WholeStory
Selection.Range.Case = wdLowerCase

Set paras = ActiveDocument.Paragraphs
para_count = paras.Count

For i = 1 To para_count

Set first_char = paras(i).Range.Characters.Item(1)
If IsLowerChar(first_char.Text) Then
first_char.Select
Selection.TypeText (UCase(first_char.Text))
End If

Next i

End Sub

Function IsLowerChar(CHR As String) As Boolean
CHR = Left(CHR, 1)
X1 = (LCase(CHR) = CHR)
X2 = (UCase(CHR) = CHR)
IsLowerChar = X1 And (Not X2)
End Function
Collapse


 
Jigar Kantharia
Jigar Kantharia  Identity Verified
India
Local time: 03:11
French to English
+ ...
TOPIC STARTER
Excellent Jul 27, 2017

This working very fast... however, at many places it did not change the case, for e.g. (actif totale et)

 
Rolf Keller
Rolf Keller
Germany
Local time: 22:41
English to German
Oops, my proposal worked too fast Jul 27, 2017

This should work fast & correct:

Sub captalize()

' captalize the first letter of each line and uncaptitalize the rest

Application.ScreenUpdating = False

Selection.WholeStory
Selection.Range.Case = wdLowerCase

Set paras = ActiveDocument.Paragraphs
para_count = paras.Count

For i = 1 To para_count
Set chars = paras(i).Range.Characters

chars_count = chars.Count
For j = 1 To chars_count<
... See more
This should work fast & correct:

Sub captalize()

' captalize the first letter of each line and uncaptitalize the rest

Application.ScreenUpdating = False

Selection.WholeStory
Selection.Range.Case = wdLowerCase

Set paras = ActiveDocument.Paragraphs
para_count = paras.Count

For i = 1 To para_count
Set chars = paras(i).Range.Characters

chars_count = chars.Count
For j = 1 To chars_count

Set curr_char = chars.Item(j)

CHR_old = curr_char.Text
CHR_new = UCase(CHR_old)
If Not (CHR_old = CHR_new) Then
curr_char.Select
Selection.TypeText CHR_new
Exit For
End If

Next j
Next i

Application.ScreenUpdating = True

End Sub

[Bearbeitet am 2017-07-27 12:22 GMT]
Collapse


 
Shouguang Cao
Shouguang Cao  Identity Verified
China
Local time: 05:41
English to Chinese
+ ...
The same thing Jul 28, 2017

Hi Rolf,

Your second version is essentially the same with mine.

Dallas


 
Pages in topic:   < [1 2]


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Macro to Capitalize the first occurring alphabet in a MS Word Table






Protemos translation business management system
Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!

The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.

More info »
Wordfast Pro
Translation Memory Software for Any Platform

Exclusive discount for ProZ.com users! Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value

Buy now! »