Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2011, 08:45 AM
powerdrum powerdrum is offline Converts the words to actual All Capital Letters not workin macro?? Windows 7 64bit Converts the words to actual All Capital Letters not workin macro?? Office 2010 32bit
Novice
Converts the words to actual All Capital Letters not workin macro??
 
Join Date: Nov 2011
Posts: 2
powerdrum is on a distinguished road
Default Converts the words to actual All Capital Letters not workin macro??

This macro below for some reason is not going through the whole document or all the words to covert, can someone help on this!!!!
We are using microsoft Word 2010.
Thanks!!




Sub Convert_AllCaps_FontFormatting()

'This macro goes through the document and checks the
'Font attributes on the Words for All Caps.
'If the attribute is found then it converts the
'words to actual All Capital Letters.

For a = 1 To ActiveDocument.Words.Count
ActiveDocument.Words(a).Select

If Selection.Font.AllCaps = True Then
Selection.Range.Case = wdUpperCase
End If

Next a
End Sub
Reply With Quote
  #2  
Old 12-08-2011, 03:31 PM
Stefan Blom's Avatar
Stefan Blom Stefan Blom is offline Converts the words to actual All Capital Letters not workin macro?? Windows 7 64bit Converts the words to actual All Capital Letters not workin macro?? Office 2010 32bit
Moderator
 
Join Date: Aug 2011
Posts: 3,902
Stefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to all
Default

I suspect you have to look at this character by character for it to work properly:


Dim c As Range

For Each c In ActiveDocument.Characters
If c.Font.AllCaps = -1 Then
c.Case = wdUpperCase
End If
Next c
__________________
Stefan Blom
Microsoft Word MVP

Microsoft 365 apps for business
Windows 11 Professional
Reply With Quote
  #3  
Old 12-08-2011, 05:06 PM
macropod's Avatar
macropod macropod is offline Converts the words to actual All Capital Letters not workin macro?? Windows 7 64bit Converts the words to actual All Capital Letters not workin macro?? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Powerdrum,

Try:
Code:
Sub Demo()
Dim MyData As DataObject, strClip As String, i As Long
Set MyData = New DataObject
With ActiveDocument.Content
  With .Find
    .ClearFormatting
    .Text = ""
    With .Font
      .SmallCaps = False
      .AllCaps = True
    End With
    With .Replacement
      .Text = ""
      .ClearFormatting
    End With
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    .Copy
    MyData.GetFromClipboard
    .Text = MyData.GetText
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
  With .Find
    .Wrap = wdFindContinue
    With .Replacement.Font
      .SmallCaps = False
      .AllCaps = False
    End With
    .Execute Replace:=wdReplaceAll
  End With
End With
End Sub
Note: You'll need to add a reference to the MS Forms object library.

Alternatively, you might prefer this simplified version, which doesn't need a reference to the MS Forms object library:
Code:
Sub Demo()
With ActiveDocument.Content
  With .Find
    .ClearFormatting
    .Text = ""
    With .Font
      .SmallCaps = False
      .AllCaps = True
    End With
    With .Replacement
      .Text = ""
      .ClearFormatting
    End With
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    .Cut
    .PasteSpecial DataType:=wdPasteText
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converts the words to actual All Capital Letters not workin macro?? Macro for highlighting specific number of words icsjohn Word VBA 2 12-07-2011 06:44 PM
Converts the words to actual All Capital Letters not workin macro?? Croatian characters such as a capital C w/ accent acute? vhindley Word 3 07-08-2011 03:39 AM
Why the "Headings" are appearing in capital letters in the Table of contents? Jamal NUMAN Word 1 05-31-2011 08:31 AM
safe sender list not workin LA1976 Outlook 0 05-23-2011 03:27 AM
MS Project able to import actual start and or actual finish date from Excel? mhacker Project 0 04-26-2010 11:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:32 AM.


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