From: Francis Hookham on 26 Jun 2008 03:21 I need to add '<B>' at the beginning and '</B>' at the end of the particular paragraph then move to the beginning of the next paragraph. The following works if the insertion point is at the beginning of the paragraph but falls down if not. I have tried various key combinations to try to get to the beginning of the paragraph but if the insertion point is already there they fall down too. Selection.HomeKey Unit:=wdLine, Extend:=wdExtend Selection.MoveLeft Unit:=wdCharacter, Count:=1 Selection.HomeKey Unit:=wdLine, Extend:=wdExtend Please help Francis Hookham Sub htmlBold() Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend Selection.Cut Selection.TypeText Text:="<B>" Selection.PasteAndFormat (wdPasteDefault) Selection.MoveLeft Unit:=wdCharacter, Count:=1 Selection.TypeText Text:="</B>" Selection.MoveRight Unit:=wdCharacter, Count:=1 End Sub
From: Doug Robbins - Word MVP on 26 Jun 2008 05:12 Use: Dim myrange As Range Set myrange = Selection.Paragraphs(1).Range myrange.Select Selection.Collapse wdCollapseEnd With myrange .End = .End - 1 .InsertBefore "<B>" .InsertAfter "</B>" End With -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "Francis Hookham" <fh.2.net(a)ntlworld.com> wrote in message news:uWHsn111IHA.5664(a)TK2MSFTNGP02.phx.gbl... >I need to add '<B>' at the beginning and '</B>' at the end of the >particular paragraph then move to the beginning of the next paragraph. The >following works if the insertion point is at the beginning of the paragraph >but falls down if not. > > I have tried various key combinations to try to get to the beginning of > the paragraph but if the insertion point is already there they fall down > too. > Selection.HomeKey Unit:=wdLine, Extend:=wdExtend > Selection.MoveLeft Unit:=wdCharacter, Count:=1 > Selection.HomeKey Unit:=wdLine, Extend:=wdExtend > > Please help > > Francis Hookham > > Sub htmlBold() > Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend > Selection.Cut > Selection.TypeText Text:="<B>" > Selection.PasteAndFormat (wdPasteDefault) > Selection.MoveLeft Unit:=wdCharacter, Count:=1 > Selection.TypeText Text:="</B>" > Selection.MoveRight Unit:=wdCharacter, Count:=1 > End Sub > > > >
From: Francis Hookham on 26 Jun 2008 06:18 Many thanks Doug and Shasur now I shall have to toss a coin to choose - both work exactly as I wanted and I have yet again learned a lot Francis
From: Gordon Bentley-Mix on 30 Jun 2008 21:06 Francis, I'm a bit late with my reply, but this sort of slipped off my radar. IMHO, I'd use Doug's solution. No offense intended to Shasur, but in any solution if you can at all avoid using the Selection object - and especially moving it - it's probably a better approach. It will be quicker (not a major problem in this application) and the screen won't jump around all over the place. Plus then you won't have to somehow relocate the cursor back to where you started. (I reckon Shasur only made such extensive use of the Selection object because you were...) -- Cheers! Gordon Uninvited email contact will be marked as SPAM and ignored. Please post all follow-ups to the newsgroup. "Francis Hookham" wrote: > Many thanks Doug and Shasur > > now I shall have to toss a coin to choose - both work exactly as I wanted > and I have yet again learned a lot > > Francis > > >
|
Pages: 1 Prev: Select a network printer from the command line Next: Using Word in ASP-Application |