Pages in topic:   [1 2] >
Macro to Capitalize the first occurring alphabet in a MS Word Table
Thread poster: Jigar Kantharia
Jigar Kantharia
Jigar Kantharia  Identity Verified
India
Local time: 11:39
French to English
+ ...
Jul 22, 2017

I am looking for a macro which can capitalize the first alphabet of a sentence in each row of MS Word tables.

For example, I have following entries.

My name is ABC
- I am from XYZ
-he works on a word document
1. hello there

The macro should give below shown result, capitalizing only the first character (only alphabets).

My name is abc
- I am from xyz
-He works on a word document
1. Hello there

Se
... See more
I am looking for a macro which can capitalize the first alphabet of a sentence in each row of MS Word tables.

For example, I have following entries.

My name is ABC
- I am from XYZ
-he works on a word document
1. hello there

The macro should give below shown result, capitalizing only the first character (only alphabets).

My name is abc
- I am from xyz
-He works on a word document
1. Hello there

Sentence case option of MS Word does not work as - I am from XYZ would become - i am from xyz


Thanks
Jigar
Collapse


 
Shouguang Cao
Shouguang Cao  Identity Verified
China
Local time: 14:09
English to Chinese
+ ...
Capitalize first letter of each paragraph Jul 22, 2017

Precondition: Each line must be separated by hard returns not soft returns.


Sub captalize()
'
' captalize the first letter of each line
'
'

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
current_char = ActiveDocument.Paragraphs(i).Range.Characters.Item(j)
If As
... See more
Precondition: Each line must be separated by hard returns not soft returns.


Sub captalize()
'
' captalize the first letter of each line
'
'

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
current_char = ActiveDocument.Paragraphs(i).Range.Characters.Item(j)
If Asc(current_char) > 64 And Asc(current_char) < 91 Then
Exit For
End If
If Asc(current_char) > 96 And Asc(current_char) < 123 Then
ActiveDocument.Paragraphs(i).Range.Characters.Item(j).Select
Selection.TypeText (UCase(current_char))
Exit For
End If
Next

Next i
End Sub


Collapse


 
Rolf Keller
Rolf Keller
Germany
Local time: 07:09
English to German
There are much more Latin letters Jul 22, 2017

Shouguang Cao wrote:

If Asc(current_char) > 64 And Asc(current_char) < 91 Then
...
If Asc(current_char) > 96 And Asc(current_char) < 123 Then

In non-English languages that use Latin letters there are 88 additional letters that don't come under these ranges. So you may want to use the LCase() & UCase() functions instead of numbers.

À Á Â Ã Ä Å Æ ...


 
Shouguang Cao
Shouguang Cao  Identity Verified
China
Local time: 14:09
English to Chinese
+ ...
Indeed Jul 23, 2017

The two lines try to find the first word character and capitalize it as the non-word characters may preceed the line.
Here is the update to include non-English letters:


Sub captalize()
'
' captalize the first letter of each line
'
'

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<
... See more
The two lines try to find the first word character and capitalize it as the non-word characters may preceed the line.
Here is the update to include non-English letters:


Sub captalize()
'
' captalize the first letter of each line
'
'

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
current_char = ActiveDocument.Paragraphs(i).Range.Characters.Item(j)
If Asc(current_char) > 64 And Asc(current_char) < 91 Then
Exit For
End If
If Asc(current_char) > 191 And Asc(current_char) < 223 Then
Exit For
End If
If Asc(current_char) > 96 And Asc(current_char) < 123 Then
ActiveDocument.Paragraphs(i).Range.Characters.Item(j).Select
Selection.TypeText (UCase(current_char))
Exit For
End If
If Asc(current_char) > 223 And Asc(current_char) < 256 Then
ActiveDocument.Paragraphs(i).Range.Characters.Item(j).Select
Selection.TypeText (UCase(current_char))
Exit For
End If
Next j

Next i
End Sub




[Edited at 2017-07-23 06:59 GMT]
Collapse


 
Jigar Kantharia
Jigar Kantharia  Identity Verified
India
Local time: 11:39
French to English
+ ...
TOPIC STARTER
suggested macro not working Jul 23, 2017

Dear Shouguang Cao,

First of all, thank you for your help. However, the macro suggested by you converts the first occurring alphabet alright... however it does not convert any other text into lower case. So here is the original text and also the text converted using the macro

- produit net bancaire
. Charges d'exploitation hors FRU
Contribution au Fonds de Résolution Unique (FRU)
Résultat brut d'exploitation
Rés. net des act. abandonnées
... See more
Dear Shouguang Cao,

First of all, thank you for your help. However, the macro suggested by you converts the first occurring alphabet alright... however it does not convert any other text into lower case. So here is the original text and also the text converted using the macro

- produit net bancaire
. Charges d'exploitation hors FRU
Contribution au Fonds de Résolution Unique (FRU)
Résultat brut d'exploitation
Rés. net des act. abandonnées

After running the macro, it gets converted as

- Produit net bancaire
. Charges d'exploitation hors FRU (This should have been converted as . Charges d'exploitation hors fru)
Contribution au Fonds de Résolution Unique (FRU) (This should have been Contribution au fonds de résolution unique (fru)
Résultat brut d'exploitation
Rés. net des act. abandonnées


Any work around for this?

Regards,
Jigar
Collapse


 
Shouguang Cao
Shouguang Cao  Identity Verified
China
Local time: 14:09
English to Chinese
+ ...
Here you go Jul 23, 2017

I wonder how I can let proz.com forum keep my indent. Look ugly but it will work. Check out the colored and neat looking version here:
http://dallascao.com/en/word-macro-vba-capitalize-1st-letter-of-each-line/


Sub captalize()

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


para_
... See more
I wonder how I can let proz.com forum keep my indent. Look ugly but it will work. Check out the colored and neat looking version here:
http://dallascao.com/en/word-macro-vba-capitalize-1st-letter-of-each-line/


Sub captalize()

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


para_count = ActiveDocument.Paragraphs.Count
For i = 1 To para_count
para_length = ActiveDocument.Paragraphs(i).Range.Characters.Count
first_char = True
For j = 1 To para_length
Set current_char = ActiveDocument.Paragraphs(i).Range.Characters.Item(j)
asc_current_char = Asc(current_char.Text)
If (asc_current_char > 64 And asc_current_char < 91) Or _
(asc_current_char > 191 And asc_current_char < 223) Then
If Not first_char Then
current_char.Select
Selection.TypeText (LCase(current_char.Text))
End If
first_char = False
End If

If (asc_current_char > 96 And asc_current_char < 123) Or _
(asc_current_char > 223 And asc_current_char < 256) Then
If first_char Then
current_char.Select
Selection.TypeText (UCase(current_char.Text))
End If
first_char = False
End If
Next j

Next i
End Sub



[Edited at 2017-07-23 07:41 GMT]
Collapse


 
Jigar Kantharia
Jigar Kantharia  Identity Verified
India
Local time: 11:39
French to English
+ ...
TOPIC STARTER
Thanks Jul 23, 2017

Hi Shouguang Cao,

Thank you so much for your help... this seems to be working.


Regards,
Jigar


 
Nikki Scott-Despaigne
Nikki Scott-Despaigne  Identity Verified
Local time: 07:09
French to English
Shorter way: select the option Jul 23, 2017

The main thing is that you have found a solution. However, I do not think you need to go to such lengths as it is an option you can select.

File
Options
Proofing
Autocorrect options
Capitalize first letter of table cells

If you need the first letter of each "-" at the start of a line ot be capitalized, then there is also an option for that which you can activtae/disactivate.

P.S. Acronyms in French are usually FRU nowadays, although
... See more
The main thing is that you have found a solution. However, I do not think you need to go to such lengths as it is an option you can select.

File
Options
Proofing
Autocorrect options
Capitalize first letter of table cells

If you need the first letter of each "-" at the start of a line ot be capitalized, then there is also an option for that which you can activtae/disactivate.

P.S. Acronyms in French are usually FRU nowadays, although you do sometimes see Fru (edited: if the acornym is pronounced as a word and eeach individual letter is not pronounced).
However, in English, it has to be FRU; all letters of the acronym must be capitalized.



[Edited at 2017-07-23 09:40 GMT

[Edited at 2017-07-23 20:04 GMT]
Collapse


 
Shouguang Cao
Shouguang Cao  Identity Verified
China
Local time: 14:09
English to Chinese
+ ...
:-)Programmers are not linguists:-) Jul 23, 2017

As a programmer I deliver what my clients ask for, and no questions asked.
Nikki Scott-Despaigne wrote:

The main thing is that you have found a solution. However, I do not think you need to go to such lengths as it is an option you can select.

File
Options
Proofing
Autocorrect options
Capitalize first letter of table cells

If you need the first letter of each "-" at the start of a line ot be capitalized, then there is also an option for that which you can activtae/disactivate.

P.S. Acronyms in French are usually FRU nowadays, although you do sometimes see FRU.
However, in English, it has to be FRU; all letters of the acronym must be capitalized.



[Edited at 2017-07-23 09:40 GMT]


 
Rolf Keller
Rolf Keller
Germany
Local time: 07:09
English to German
KISS (Keep it simple and straightforward) is your friend Jul 23, 2017

Shouguang Cao wrote:

The two lines try to find the first word character and capitalize it as the non-word characters may preceed the line.
Here is the update to include non-English letters:


Nevertheless the macro depends on language-dependent numbers which will not work for non-Latin, e. g. for Cyrilic or Greek.

What about an universal technology like the following?

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

This way your macro will work language-independently. And it will be shorter, more clearly laid out, and more fault-proof.


 
Shouguang Cao
Shouguang Cao  Identity Verified
China
Local time: 14:09
English to Chinese
+ ...
Amazing Jul 23, 2017

This one is perfect now. Thanks Rolf. Chinese doesn't have the difference of upper case and lower case and English happens to be the only foreign language I know.
P.S. I checked out the tool Omni Look-up you authored. It looks great. I thought I was the best programmer among translators, or best translator among programmers (:joking). You got it self-signed and it passed the chrome download warning as well as microsoft smartscreen.

Sub captalize()

' captalize
... See more
This one is perfect now. Thanks Rolf. Chinese doesn't have the difference of upper case and lower case and English happens to be the only foreign language I know.
P.S. I checked out the tool Omni Look-up you authored. It looks great. I thought I was the best programmer among translators, or best translator among programmers (:joking). You got it self-signed and it passed the chrome download warning as well as microsoft smartscreen.

Sub captalize()

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


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

If IsLowerChar(current_char.Text) Then
If first_char Then
current_char.Select
Selection.TypeText (UCase(current_char.Text))
End If
first_char = False
ElseIf IsUpperChar(current_char.Text) Then
If Not first_char Then
current_char.Select
Selection.TypeText (LCase(current_char.Text))
End If
first_char = False
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

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






Rolf Keller wrote:

Shouguang Cao wrote:

The two lines try to find the first word character and capitalize it as the non-word characters may preceed the line.
Here is the update to include non-English letters:


Nevertheless the macro depends on language-dependent numbers which will not work for non-Latin, e. g. for Cyrilic or Greek.

What about an universal technology like the following?

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

This way your macro will work language-independently. And it will be shorter, more clearly laid out, and more fault-proof.



[Edited at 2017-07-23 16:21 GMT]
Collapse


 
Nikki Scott-Despaigne
Nikki Scott-Despaigne  Identity Verified
Local time: 07:09
French to English
Fair enough ;-) Jul 23, 2017

Shouguang Cao wrote:

As a programmer I deliver what my clients ask for, and no questions asked.
Nikki Scott-Despaigne wrote:

The main thing is that you have found a solution. However, I do not think you need to go to such lengths as it is an option you can select.

File
Options
Proofing
Autocorrect options
Capitalize first letter of table cells

If you need the first letter of each "-" at the start of a line ot be capitalized, then there is also an option for that which you can activtae/disactivate.

P.S. Acronyms in French are usually FRU nowadays, although you do sometimes see FRU.
However, in English, it has to be FRU; all letters of the acronym must be capitalized.



[Edited at 2017-07-23 09:40 GMT]


I might be wrong, but as you guess correctly, I am not a programmer. I was just suggesting what I (mis?) understood as a request to achieve a particular aim and thought that this was a more straightforward way to achieve it.


 
Shouguang Cao
Shouguang Cao  Identity Verified
China
Local time: 14:09
English to Chinese
+ ...
I wanted to ask why too Jul 24, 2017

I also don't understand why jigsmk wanted to decapitalize the acronyms but he requests to capitalize the first letter and decapitalize the rest of each line.

Nikki Scott-Despaigne wrote:

Shouguang Cao wrote:

As a programmer I deliver what my clients ask for, and no questions asked.
Nikki Scott-Despaigne wrote:

The main thing is that you have found a solution. However, I do not think you need to go to such lengths as it is an option you can select.

File
Options
Proofing
Autocorrect options
Capitalize first letter of table cells

If you need the first letter of each "-" at the start of a line ot be capitalized, then there is also an option for that which you can activtae/disactivate.

P.S. Acronyms in French are usually FRU nowadays, although you do sometimes see FRU.
However, in English, it has to be FRU; all letters of the acronym must be capitalized.



[Edited at 2017-07-23 09:40 GMT]


I might be wrong, but as you guess correctly, I am not a programmer. I was just suggesting what I (mis?) understood as a request to achieve a particular aim and thought that this was a more straightforward way to achieve it.


 
Jigar Kantharia
Jigar Kantharia  Identity Verified
India
Local time: 11:39
French to English
+ ...
TOPIC STARTER
slowness Jul 24, 2017

Hi,

I am converting my documents like this to remove the impact of case sensitivity. So I will have my TMs as well as the documents I receive in the same case. So I am trying and testing this option as well as othe case options.

The macro is working fine, however, to convert a 36 page document, it has already taken more than 45 minutes and then shows as Not Responding. Is it possible to write it in a way which can do this task fast?


Thanks and Regard
... See more
Hi,

I am converting my documents like this to remove the impact of case sensitivity. So I will have my TMs as well as the documents I receive in the same case. So I am trying and testing this option as well as othe case options.

The macro is working fine, however, to convert a 36 page document, it has already taken more than 45 minutes and then shows as Not Responding. Is it possible to write it in a way which can do this task fast?


Thanks and Regards,
Jigar
Collapse


 
Ben Senior
Ben Senior  Identity Verified
Germany
Local time: 07:09
German to English
Turn screen updating off Jul 24, 2017

To speed up the execution of any code in Office VBA turn off screen updating by adding the following line of code at the top of your module:

Application.ScreenUpdating = False

I haven't tested the code posted by Shouguang Cao, but it should improve performance.

Regards,

Ben

[Edited at 2017-07-24 12:11 GMT]

[Edited at 2017-07-24 12:12 GMT]


 
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 »
TM-Town
Manage your TMs and Terms ... and boost your translation business

Are you ready for something fresh in the industry? TM-Town is a unique new site for you -- the freelance translator -- to store, manage and share translation memories (TMs) and glossaries...and potentially meet new clients on the basis of your prior work.

More info »