for an Escape Room Puzzle I want to change text into coneiform symbols. I could manually replace characters, but I'd rather do it by macro.
Up until now, I failesd miserably.
I am using Esagil Font, which can be found here: https://www.hethport.uni-wuerzburg.de/cuneifont/download/Esagil.ttf)
Unicode Numbers for Cubeiform can also be found in this wiki here https://en.wikipedia.org/wiki/Cuneiform_(Unicode_block)
I can change text with Unicode by using the following code
Sub UniCodeSymbol()
Selection.TypeText Text:="12041"
Selection.ToggleCharacterCode
Selection.Font.Name = "Esagil"
End Sub
I am also able to replace text
Sub Replace
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "0"
.Replacement.Text = "1241E"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
But I am unable to combine both. I found the ChrW() method, replacing ".Replacement.Text = "1241E"" to ".Replacement.Text = ChrW(-10232)", but the ChrW value I found for the Symbol, does not give me the symbol.
When i do a test Maro for the ChrW method it yields the following:
Sub Makro1()
Selection.InsertSymbol Font:="Esagil", CharacterNumber:=-10231, Unicode:= _
True
Selection.InsertSymbol Font:="Esagil", CharacterNumber:=-9191, Unicode:= _
True
End Sub
It uses 2 ChrW. I have no idea how to put that in a Replace macro.
Can anyone help me? Thanks a lot in advance. Cheers.
Related
I'm looking into creating a macro that would search for a set of many king o texts variations and change it to something else.
For examples:
Find a paragraph followed by the word Art1, Art1., etc = ˆpArt1, ˆpArt1., ˆpArt 1, ˆpArt I, so on... replace with the string ˆpArt. 1. in bold.
So basically, I have many variations of an occurrence that I need to change so a specific text, and I would be constantly feeding this string to look for many variations on the search to replace with something I would define.
Any ideias?
this is what I'm trying with no success:
Sub Macro1()
'
' Macro1 Macro
'
'
Dim Arts1 As String
Arts1 = Split(("^p1o", "^p1 o")
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = Arts1
.Replacement.Text = "^pArtigo 1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
You could use the .replace function for the string.
"^pArt1 Art1".replace("Art1", "TODO")
I have a question about a problem i need do solve.
I have a word doc, on which i want to run a search and replace query.
But i dont want to change the actual text, i want to put the changed text
in the clipboard and leave the actual one unchanged.
Sub SearchAndReplace()
' marks all bold words,italic words, underlined
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
Selection.Find.Font.Italic = True
Selection.Find.Font.Underline = wdUnderlineSingle
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "[test]^&[/test]"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Cautious:
I guess there are better ways to achieve what you want to do as this is not proper coding. (Also as the clipboard only has a limit of 24 items), but for the sake of making your code works, here is my answer:
To copy the text in the clipboard instead of replacing it, you can just use the .copy method.
If you replace your line:
Selection.Find.Execute Replace:=wdReplaceAll
by
Dim iCount As Long
Selection.Find.Execute
Selection.Copy
Do While Selection.Find.Found = True And iCount < 1000
iCount = iCount + 1
Selection.Find.Execute
Selection.Copy
Loop
it should work.
The code is simply copying the item found after each search.
Selection.Find.Execute searches the next itteration of the search every time it appears in the code.
Once there are no search found anymore (or there are too many searches), the loop will stop.
Am a beginner in VBA. I need to store only italic text from a specific paragraph into a variable. How to do it?
you can use the following example to look for a text range with the desired formatting and then process them by storing them in the variable used each time you can append the new text with the previous content of the variable.
Eg:
selection_range.Style = _
ActiveDocument.Styles("Text_Format_To_Search")
where
Text_Format_To_Search will be replaced by the text formatting you need to search.
reference from:- http://www.vb-helper.com/howto_format_code_in_word.html
Thanks to KazJaw. Finally I got the solution and I have pasted below
sub test()
ActiveDocument.Paragraphs(2).Range.Select
Selection.Find.Font.Italic = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
str_italic = Selection.Range.Text
End Sub
If you looking to find italicized text and store only the text in a variable, then you can try:
Sub findItal()
Dim italText As String
'Find italic text
With Selection.Find
.ClearFormatting
.Font.Italic = True
.Wrap = wdFindStop
.Execute
If .Found = True Then
italText = Selection.Range.Text
End If
End With
End Sub
I have a Word document with blocks of text marked with styles called "Princple" and "BusinessRule". These blocks of text are scattered throughout the document. I would like to find and copy these blocks to a separate document in the order in which they appear. The code I am using is:
Dim SelStyle As String
'SelStyle = "Principle"
SelStyle = "BusinessRule"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Style = SelStyle
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Copy
Windows("Document1").Activate
Selection.TypeParagraph
Selection.PasteAndFormat (wdFormatPlainText)
Selection.TypeParagraph
Windows("mainDoc.docx").Activate
Selection.MoveRight Unit:=wdCharacter, Count:=1
As you see, this is a manual process: first un-comment the Principle, extract all of those, then comment Princple and uncomment BusinessRule. Not great. Is there any way to search for .Style="Principle" or .Style="BusinessRule" so I get them all in sequence? (And, secondarily, if you have a suggestion for looping through the whole document to do this, I would be additionally grateful. :-))
Thanks - Bill
Why not store the values in an array?
Sub Sample()
Dim SelStyle(1) As String
SelStyle(0) = "Principle"
SelStyle(1) = "BusinessRule"
For i = 0 To 1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Style = SelStyle(i)
'
'~~> Rest of your code
'
Next i
End Sub
fwiw, I changed my approach on this. Instead of searching for styles, I go through each paragraph in the document and see if the style is "Principle" or "BusinessRule". If true, then I copy/paste the paragraph. So not only do I get the "or", but I also get them in order.
I make a several page word document every week. I copy text from a PDF and paste it into a word document, I then format the text that I pasted.
This takes a long time and i would like to automate it.
I need a macro or some code to select specific text, then make that text bold. The specific text i need to bold is what i call a scrap code.
There are 60 different codes. For example "FIPS", or "LILL".
Something like this:
Sub A()
'
' a Macro
'
'
Dim A(3) As String
A(1) = "code1"
A(2) = "code2"
A(3) = "code3"
For i = 1 To 3
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Replacement.Font.Bold = True
.Execute FindText:=A(i), ReplaceWith:=A(i), Format:=True, _
Replace:=wdReplaceAll
End With
Next i
End Sub
HTH!
Edit
To switch dollar amounts to bold
Sub a()
'
' a Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Bold = True
With Selection.Find
.Text = "$([0-9.,]{1,})"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
I would suggest recording a macro.
Then do all the modifications and formatting.
Finally, look at the code of the macro and see how it did it.
The one thing you need to figure out is how you logically want to locate the text you want to bold.
Is it a specific line? Is it at the beginning of a known word?
Once you have that answered, you can combine it with the code of the macro and automate the task.