Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Wildcard "special" searches
(Word2007)
My authors are European, so they love to put their periods and commas after their footnote references, but that's not how we Americans do it. I'm getting tired of manually moving the punctuation around (and the Transpose macro results in a superscript period before the footnote reference, which isn't an improvement). Word tells me that I cannot use both ^f and Wildcards in a (Find-)Replace, so how can I automate this procedure? (Is it possible to modify the Transpose macro to not affect the Superscript status of the characters involved, since it's unlikely in the extreme that a typo would involve superscripting!) (Here's the text of the macro that was provided here years ago; it was modified from the original because it was taking longer and longer to work as a file got bigger, so a checking operation was removed.) Sub Transpose() Dim oRng As Range Dim sText As String Dim Msg1 As String Dim Msg2 As String Dim Msg3 As String Dim MsgTitle As String Msg1 = "You must place the cursor between " & _ "the 2 characters to be transposed!" Msg2 = "There are no characters to transpose?" Msg3 = "There is no document open!" MsgTitle = "Transpose Characters" On Error GoTo ErrorHandler Set oRng = Selection.Range Select Case Len(oRng) Case Is = 0 If oRng.Start = oRng.Paragraphs(1).Range.Start Then MsgBox Msg1, vbCritical, MsgTitle Exit Sub End If If oRng.End = oRng.Paragraphs(1).Range.End - 1 Then MsgBox Msg1, vbCritical, MsgTitle Exit Sub End If With oRng .Start = .Start - 1 .End = .End + 1 .Select sText = .Text End With Case Is = 1 MsgBox Msg1, vbCritical, MsgTitle Exit Sub Case Is = 2 sText = Selection.Range.Text Case Else MsgBox Msg1, vbCritical, MsgTitle Exit Sub End Select With Selection If .Range.Characters(1).Case = 1 _ And .Range.Characters(2).Case = 0 Then .TypeText UCase(Mid(sText, 2, 1)) & _ LCase(Mid(sText, 1, 1)) Else .TypeText Mid(sText, 2, 1) & _ Mid(sText, 1, 1) End If .MoveLeft wdCharacter End With End ErrorHandler: If Err.Number = 4248 Then MsgBox Msg3, vbCritical, MsgTitle End If End Sub |
#2
|
|||
|
|||
I modified the code slightly. This should solve your problem.
Sub Transpose() Dim oRng As Range Dim sText As String Dim Msg1 As String Dim Msg2 As String Dim Msg3 As String Dim MsgTitle As String Msg1 = "You must place the cursor between " & _ "the 2 characters to be transposed!" Msg2 = "There are no characters to transpose?" Msg3 = "There is no document open!" MsgTitle = "Transpose Characters" On Error GoTo ErrorHandler Set oRng = Selection.Range Select Case Len(oRng) Case Is = 0 If oRng.Start = oRng.Paragraphs(1).Range.Start Then MsgBox Msg1, vbCritical, MsgTitle Exit Sub End If If oRng.End = oRng.Paragraphs(1).Range.End - 1 Then MsgBox Msg1, vbCritical, MsgTitle Exit Sub End If With oRng .Start = .Start - 1 .End = .End + 1 .Select sText = .Text End With Case Is = 1 MsgBox Msg1, vbCritical, MsgTitle Exit Sub Case Is = 2 sText = Selection.Range.Text Case Else MsgBox Msg1, vbCritical, MsgTitle Exit Sub End Select With Selection If .Range.Characters(1).Case = 1 _ And .Range.Characters(2).Case = 0 Then .TypeText UCase(Mid(sText, 2, 1)) & _ LCase(Mid(sText, 1, 1)) ElseIf .Range.Characters(1).Font.Superscript = True _ And .Range.Characters(2).Font.Superscript = False Then .TypeText UCase(Mid(sText, 2, 1)) & _ LCase(Mid(sText, 1, 1)) Selection.MoveStart Unit:=wdCharacter, Count:=-2 Selection.Characters(1).Font.Superscript = False Selection.Characters(2).Font.Superscript = True Else .TypeText Mid(sText, 2, 1) & _ Mid(sText, 1, 1) End If .MoveLeft wdCharacter End With End ErrorHandler: If Err.Number = 4248 Then MsgBox Msg3, vbCritical, MsgTitle End If End Sub Quote:
|
#3
|
|||
|
|||
Where are you placing the cursor ? Please try the macro with the cursor anywhere on the line where the footnote reference is located but before the footnote reference. It should work.
Please let me know if it doesn't. If not, I will code for placing the cursor between the footnote reference and the next character. If you can get this macro to work, it should be even more convenient for you. |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Wildcard "special" searches
On Jul 28, 11:19*pm, Venky62
T wrote: Where are you placing the cursor ? Please try the macro with the cursor anywhere on the line where the footnote reference is located but before the footnote reference. It should work. I placed the cursor a few characters before the footnote reference, on the same line. I just tried it again, and the Visual Basic window opened, with the line "Cut" highlighted and a little box reading "Compile error: Sub or Function not defined." Please let me know if it doesn't. If not, I will code for placing the cursor between the footnote reference and the next character. If you can get this macro to work, it should be even more convenient for you. Indeed. |
#5
|
|||
|
|||
I can't figure it out. Maybe something was left out while copying my code? Is there a period before the cut statement? Like ".cut" ?
Could you upload your document so that I could see where the error is creeping in? Quote:
|
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Wildcard "special" searches
On Jul 29, 10:48*am, Venky62
T wrote: I can't figure it out. Maybe something was left out while copying my code? Is there a period before the cut statement? Like ".cut" ? Nope. It's directly below two lines in green. Could you upload your document so that I could see where the error is creeping in? You want me to upload my normal.dotm template somewhere? Where? I installed the macro simply by copying your text from the newsgroup to the clipboard, then to a Notepad file; then copied it from the Notepad file to the template (following Greg Mayor's instructions, which have worked all the times people have posted useful macros here before). Peter T. Daniels;492930 Wrote: On Jul 28, 11:19*pm, Venky62 wrote:- Where are you placing the cursor ? Please try the macro with the cursor anywhere on the line where the footnote reference is located but before the footnote reference. It should work.- I placed the cursor a few characters before the footnote reference, on the same line. I just tried it again, and the Visual Basic window opened, with the line "Cut" highlighted and a little box reading "Compile error: Sub or Function not defined." - Please let me know if it doesn't. If not, I will code for placing the cursor between the footnote reference and the next character. If you can get this macro to work, it should be even more convenient for you.- Indeed. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Logical OR in Word wildcard searches | Microsoft Word Help | |||
In "Paste Special", Can I set "Unformatted Text" as the first choi | Microsoft Word Help | |||
How to default to "Unformatted Text" in "Paste Special" in Word 20 | Microsoft Word Help | |||
Wildcard file searches | New Users | |||
specific searches in word documents, ie "Trust C" | Microsoft Word Help |