#1
|
|||
|
|||
replace letters by font without losing format
hello dear members kindly need your help in this senario i've files need to change character by font name to another and not loos style and format or change letter case. so, need to make external file contain those paires of text, if possible, or at lest define this in code as lest like (! = A) (1 = a) example, if we have ! (times new roman font) replace to (A) tahoma font. external table help me to add any text without change code everytime, but could we make this table in excel or word file, show only by password or something secured many thanks for your help. bero |
#2
|
||||
|
||||
Hi bero,
It really isn't clear what you're trying to do. You mention changing fonts, but not formatting. That's hard to do and is often impossible, since the letter widths and heights in one font are rarely the same as in another font. You also mention the use of a file with a table and the needs to process multiple documents. For a Word macro that uses an Excel workbook to hold Find/Replace expressions for use in multiple documents, see: https://www.msofficeforums.com/word-...html#post34254
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
hello dear
all i mean need to find a letter by a specific font and replace it by another letter and change its font name too, without change letter case (capital/small) or font size or style (regular, italic..) thanks |
#4
|
||||
|
||||
You can do that using Find/Replace, without the need for any vba. Simply specify the character & font to find and the character and font it should be replaced with.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
ok. i know i able to do this by find and replace without vba,
but i've about more than 100 character, and need to do this task in many files. so pleasure if you can help me. thanks |
#6
|
||||
|
||||
You could use code like the following, but, if you're updating whole paragraphs, you really should do so by changing the paragraph Style; even for individual characters, if they're not in the same font as the paragraph Style, you should redefine them using a character Style.
Code:
Sub UpdateDocuments() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, wdDoc As Document strFolder = GetFolder If strFolder = "" Then Exit Sub strFile = Dir(strFolder & "\*.doc", vbNormal) While strFile <> "" Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) With wdDoc.Range.Find .ClearFormatting .Text = "[A-Za-z0-9]" .Font.Name = "Times New Roman" With .Replacement .ClearFormatting .Text = "^&" .Font.Name = "Tahoma" End With .Forward = True .Wrap = wdFindContinue .Format = True .MatchWildcards = True .Execute Replace:=wdReplaceAll End With wdDoc.Close SaveChanges:=True strFile = Dir() Wend Set wdDoc = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function PS: Don't store the file containing the macro in the same folder as the files to be processed.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
but could i use such code with excel sheet which contains paires of text i want to find it and replace by another and change its font as the above code
thanks |
#8
|
||||
|
||||
Why would you want to use an Excel workbook, if all you're doing is changing the font? You would only need an Excel workbook if you're changing the actual characters or whole strings to something else. Even then, you don't necessarily need to use Excel or an external file; For changes that are always the same, it's possible to encode the Find & Replace strings into the actual code.
You need to say clearly what it is you're trying to achieve. So far, your posts have been quite inconsistent about that.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Quote:
yes sure i want to replace the character depend on font too example: i've file most of its text writen by times-new-roman, all i need make excel sheet contain find text and its replacement and change any character its font times-new-roman to tahoma as its replacement in excel in breef font converting from text to another wish i help to explain the task |
#10
|
||||
|
||||
Quote:
As I have already said, twice now, if all you're doing is changing the font for some (or all) characters from Times New Roman to Tahoma, you don't need anything more than the macro I posted in post #6. Indeed, if you're doing this for a whole document, simply change the Style definitions.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
dear Paul
can i upload document to show you what i want exactly? just let me know how i add attach to this post. |
#12
|
||||
|
||||
You can attach a document to a post via the paperclip symbol on the 'Go Advanced' tab.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
dear Paul
attached sample file in word and table in excel wish it possible to do this sanario thanks for your care |
#14
|
||||
|
||||
So, notwithstanding all that you've posted before, you don't want only to change the font - in some cases you want to change the letters to something else as well. In that case, you can use the macro in the link I posted in post #2 in this thread. All you need to add to the code is the specification for the fonts to find and replace. For example, by adding:
Code:
.Font.Name = "Tahoma" .Replacement.Font.Name = "IndexBlack" .Text = Split(xlFList, "|")(I) You also need to delete: .MatchWholeWord = True
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
dear paul
many thanks, this what i need to do. sorry for bad explnation. please, may better if i put excel file beside the documents and set path to this folder and no need to choose it every time i use macro. below the text i edited in your code: i think we need to delete .clear formatting ? With .Find .Font.Name = "Tahoma" ' need to delete this line?, .ClearFormatting .Replacement .Font.Name = "IndexBlack" ' need to delete this line .ClearFormatting ' might use it later .MatchWholeWord = True .MatchCase = True many thanks |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to replace digits with letters | Bananabean | Word VBA | 6 | 09-14-2013 09:28 PM |
How to replace all font occurencies by another (e.g. Arial-->Courier) | pstein | Word | 1 | 04-30-2013 05:58 AM |
Find and Replace maintain format | winningson | Word | 3 | 01-19-2013 05:38 AM |
Format Font | herbhh | Word | 10 | 05-23-2011 08:29 AM |
How do I import text columns with specified spacing between words w/o losing format? | Fucius | Word | 0 | 08-09-2010 06:23 PM |