From: mccaskey on 28 Apr 2007 16:59 This is too weird. Open a new word document. Enter a few characters. Open VB and enter this subroutine: Sub deleteChar() Dim a as Range Set a = ActiveDocument.Range(Start:=1, End:=2) a.Delete End Sub Run the routine. As expected, the second character of your string will be deleted . . . .. . . unless the first character is ! and the second is a space, in which case nothing happens. If the first character is ! and the second is not a space, the routine will replace your second character with a space. The same happens if the first character is a right double quotation mark (Alt + 0148). What's going on? Can anyone else reproduce this? I've tried it with two releases of Word 2003.
From: Jean-Guy Marcil on 28 Apr 2007 22:16 mccaskey was telling us: mccaskey nous racontait que : > This is too weird. > > Open a new word document. Enter a few characters. > > Open VB and enter this subroutine: > > Sub deleteChar() > Dim a as Range > Set a = ActiveDocument.Range(Start:=1, End:=2) > a.Delete > End Sub > > Run the routine. As expected, the second character of your string will > be deleted . . . > > . . . unless the first character is ! and the second is a space, in > which case nothing happens. > > If the first character is ! and the second is not a space, the routine > will replace your second character with a space. > > The same happens if the first character is a right double quotation > mark (Alt + 0148). > > What's going on? > > Can anyone else reproduce this? I've tried it with two releases of > Word 2003. Yeah, I see it too. Maybe it has to do with the fact that Word sometimes interprets some characters as "special" and makes them impossible to delete through VBA... like the � immediately preceding a table which can be problematic. In fact, you will see this behaviour with any punctuation mark, not just the "!". I guess Word sees the space following a punctuation mark as an essential boundary between words and makes it difficult to delete... In your case, it is easily fixed with: Dim a As Range Set a = ActiveDocument.Range(Start:=1, End:=2) a.Text = "" -- Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE(a)CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
From: mccaskey on 28 Apr 2007 22:44 On Apr 28, 7:16 pm, "Jean-Guy Marcil" <DontEvenTry(a)NoSpam> wrote: > mccaskey was telling us: > mccaskey nous racontait que : > > > > > This is too weird. > > > Open a new word document. Enter a few characters. > > > Open VB and enter this subroutine: > > > Sub deleteChar() > > Dim a as Range > > Set a = ActiveDocument.Range(Start:=1, End:=2) > > a.Delete > > End Sub > > > Run the routine. As expected, the second character of your string will > > be deleted . . . > > > . . . unless the first character is ! and the second is a space, in > > which case nothing happens. > > > If the first character is ! and the second is not a space, the routine > > will replace your second character with a space. > > > The same happens if the first character is a right double quotation > > mark (Alt + 0148). > > > What's going on? > > > Can anyone else reproduce this? I've tried it with two releases of > > Word 2003. > > Yeah, I see it too. > > Maybe it has to do with the fact that Word sometimes interprets some > characters as "special" and makes them impossible to delete through VBA... > like the ¶ immediately preceding a table which can be problematic. In fact, > you will see this behaviour with any punctuation mark, not just the "!". I > guess Word sees the space following a punctuation mark as an essential > boundary between words and makes it difficult to delete... > In your case, it is easily fixed with: > > Dim a As Range > Set a = ActiveDocument.Range(Start:=1, End:=2) > a.Text = "" > > -- > > Salut! > _______________________________________ > Jean-Guy Marcil - Word MVP > jmarcilREM...(a)CAPSsympatico.caTHISTOO > Word MVP site:http://www.word.mvps.org Yes, I see it happens with ? also. Thanks for the solution! I should have thought of that . . . John
From: "Tony Jollans" My forename at my surname dot on 29 Apr 2007 16:34 It looks as though the delete does happen - after it, the range starts at 1 and ends at 1 and its Text is "", but Word decides it is necessary to insert a new space in the document (but not in the range). The behaviour is also in the UI. Select the characters you would set the Range to and press Delete and the space appears (or reappears). -- Enjoy, Tony Jollans Microsoft Word MVP "Jean-Guy Marcil" <DontEvenTry(a)NoSpam> wrote in message news:OVF05RgiHHA.4496(a)TK2MSFTNGP05.phx.gbl... > mccaskey was telling us: > mccaskey nous racontait que : > >> This is too weird. >> >> Open a new word document. Enter a few characters. >> >> Open VB and enter this subroutine: >> >> Sub deleteChar() >> Dim a as Range >> Set a = ActiveDocument.Range(Start:=1, End:=2) >> a.Delete >> End Sub >> >> Run the routine. As expected, the second character of your string will >> be deleted . . . >> >> . . . unless the first character is ! and the second is a space, in >> which case nothing happens. >> >> If the first character is ! and the second is not a space, the routine >> will replace your second character with a space. >> >> The same happens if the first character is a right double quotation >> mark (Alt + 0148). >> >> What's going on? >> >> Can anyone else reproduce this? I've tried it with two releases of >> Word 2003. > > Yeah, I see it too. > > Maybe it has to do with the fact that Word sometimes interprets some > characters as "special" and makes them impossible to delete through VBA... > like the � immediately preceding a table which can be problematic. In > fact, you will see this behaviour with any punctuation mark, not just the > "!". I guess Word sees the space following a punctuation mark as an > essential boundary between words and makes it difficult to delete... > In your case, it is easily fixed with: > > Dim a As Range > Set a = ActiveDocument.Range(Start:=1, End:=2) > a.Text = "" > > > > -- > > Salut! > _______________________________________ > Jean-Guy Marcil - Word MVP > jmarcilREMOVE(a)CAPSsympatico.caTHISTOO > Word MVP site: http://www.word.mvps.org >
From: Lene Fredborg on 29 Apr 2007 18:42
I tested the macro yesterday and found that it always deleted the text (regardless of ! etc.). However, I now remember that I have previously experienced related problems with spaces being inserted and deletion not working. I then found that the problems were caused by the "Smart cut and paste" option in Tools > Options > Edit tab being _turned on_. As soon as that option was turned off, everything worked as expected. Normally, I have the "Smart cut and paste" option turned off because of such problems. I just tested the macro again with "Smart cut and paste" _turned on_ and the problem described by the OP appeared. In VBA, I have previously handled the problem by turning off "Smart cut and paste" before executing operations that could else fail. I have saved the user's original setting of the option and reapplied it afterwards. The code lines for this could be: Before the operation: Dim OrigSmartCutAndPaste As Boolean Options.SmartCutPaste = False After the operation: Options.SmartCutPaste = OrigSmartCutAndPaste NOTE: I have found that there are two properties that can be used to turn off the "Smart cut and paste" option: "SmartCutPaste" and "PasteSmartCutPaste". I have used "SmartCutPaste" because I found that "PasteSmartCutPaste" does not exist in Word 2000 (and earlier I think). In general, my experience is the all options with the word "smart" in their names are causing more trouble than most other options - not least in relation to VBA (which I do not find smart…) . -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "mccaskey" wrote: > This is too weird. > > Open a new word document. Enter a few characters. > > Open VB and enter this subroutine: > > Sub deleteChar() > Dim a as Range > Set a = ActiveDocument.Range(Start:=1, End:=2) > a.Delete > End Sub > > Run the routine. As expected, the second character of your string will > be deleted . . . > > .. . . unless the first character is ! and the second is a space, in > which case nothing happens. > > If the first character is ! and the second is not a space, the routine > will replace your second character with a space. > > The same happens if the first character is a right double quotation > mark (Alt + 0148). > > What's going on? > > Can anyone else reproduce this? I've tried it with two releases of > Word 2003. > > |