Home |
Search |
Today's Posts |
#15
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
macro for transposing letters Supress "Opening this document with run the following SQL command"
Yes you can remove the references to Msg2 as they are now redundant. You can
change the references to Msg3 to Msg2 if you wish, but it will work just the same without. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org "Peter T. Daniels" wrote in message ... It seems you deleted one line near the beginning and three lines near the end. Can I also remove the lines containing or mentioning "Msg2" at the top? Or would all the "Msg3" mentions have to be changed to "Msg2"? On Aug 29, 3:29 am, "Graham Mayor" wrote: The delay is attributable to the character count used as part of the error checking. You can remove that part of the error checking and it will respond instantly - provided there are characters to transpose when you run it. 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 "Peter T. Daniels" wrote in ... Turns out it works at normal speed in a small (10-p.) document; the one it's slow in is 180 pp. But since the pair of characters it works on is the two characters on either side of the cursor (or two selected characters), why would it need to search the entire file? On Aug 22, 8:45 am, "Peter T. Daniels" wrote: Here's the code: SubTranspose() 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 totranspose?" Msg3 = "There is no document open!" MsgTitle = "TransposeCharacters" On Error GoTo ErrorHandler If ActiveDocument.Characters.Count 2 Then 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 Else MsgBox Msg2, vbCritical, MsgTitle End If End ErrorHandler: If Err.Number = 4248 Then MsgBox Msg3, vbCritical, MsgTitle End If End Sub On Aug 22, 1:57 am, "Graham Mayor" wrote: I have not been away With such low traffic, there have been few opportunities to comment. I don't remember the particular macro, but I don't use Windows 7 so cannot check it out. If you post the code, someone else may be able to check it. -- Graham Mayor - Word MVP My web sitewww.gmayor.com Word MVP web sitehttp://word.mvps.org "Peter T. Daniels" wrote in ... On Aug 21, 9:10 am, "Graham Mayor" wrote: Agreed, the forums are poor, but they are the future ... unless everyone come back here Glad to see you back here -- do you have any idea why the macro you (I'm pretty sure) provided for transposing two letters works _nearly_ immediately on Word2007 on Vista, but very very slowly on Word2007 on Windows 7, on the laptop whose CPU is otherwise rather faster than the CPU in the old IBM ThinkCentre desktop? [followup set]-- |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Opening this will run the following SQL command | Mailmerge | |||
How to prevent sql command warning when opening merge document | Mailmerge | |||
"Opening this document will run the following SQL command" prompt problem | Mailmerge | |||
MS Word Warning on start up run SQL command - How to stop? | Microsoft Word Help | |||
Word Merge "opening this document will run the following SQL comma | Mailmerge |