Selecting text in a document - 130262

Hi, I have a macro which finds a certain piece of text in the document and 
then moves down a line and then selects all the text between that and the end 
of the document and the selected text is later sent out in an email. This has 
been working for some time but I have recently had some problems because the 
text is not being selected as before (extendmode on?) and I am sending out 
blank emails.

The code fragment that I use to select the text is as follows

        Selection.HomeKey wdStory
        Selection.Find.Execute "Issued at"        
            Selection.MoveDown wdLine, 1
            Selection.EndKey wdStory, wdExtend
            Selection.Copy
        varMessageStart = Selection


I have thought that there may be a problem when extendmode is in operation 
(accidentlally)  and the text is not being highlighted. I have thought of 
trying to set a range from where the cursor is after the "find.execute" and 
the "Linedown" to the end of the document and avoiding having to highlight 
the text but I don't know how many characters will be in the first few lines 
of the document. 

Is there any way to set a range from the cursor point to the end of the 
document.
or what is a foolproof way of ensuring that the extend mode is off and that 
the selection will always include the text I want to copy?

Thanks 

Phil
0
Utf
11/25/2009 12:49:03 PM
word.vba.general 1023 articles. 1 followers. Follow

1 Replies
1020 Views

Similar Articles

[PageSpeed] 25

Hi Phil,

Your code selects the text after a line containing "Issued at" until the end 
of a document and copies it to the clipboard. It might be that you have 
selected formatted text in Word and didn't clear the formatting. Your code 
won't find the search string on such a computer. For this reason, calls to 
Selection.Find.Execute should always be preceded by a call to ClearFormatting 
as in the following.

        Selection.HomeKey wdStory
        Selection.Find.ClearFormatting
        Selection.Find.Execute "Issued at"
        Selection.MoveDown wdLine, 1
        Selection.EndKey wdStory, wdExtend
        Selection.Copy

The code that you provided does not show how the selected text is copied 
into the e-mail messages, so I can't say that you don't have a problem in 
that part of the code. For one thing, the last line that you sent doesn't 
make any sense to me.

-- 
Hope this helps,
Pesach Shelnitz 


"Phil Stokes" wrote:

> Hi, I have a macro which finds a certain piece of text in the document and 
> then moves down a line and then selects all the text between that and the end 
> of the document and the selected text is later sent out in an email. This has 
> been working for some time but I have recently had some problems because the 
> text is not being selected as before (extendmode on?) and I am sending out 
> blank emails.
> 
> The code fragment that I use to select the text is as follows
> 
>         Selection.HomeKey wdStory
>         Selection.Find.Execute "Issued at"        
>             Selection.MoveDown wdLine, 1
>             Selection.EndKey wdStory, wdExtend
>             Selection.Copy
>         varMessageStart = Selection
> 
> 
> I have thought that there may be a problem when extendmode is in operation 
> (accidentlally)  and the text is not being highlighted. I have thought of 
> trying to set a range from where the cursor is after the "find.execute" and 
> the "Linedown" to the end of the document and avoiding having to highlight 
> the text but I don't know how many characters will be in the first few lines 
> of the document. 
> 
> Is there any way to set a range from the cursor point to the end of the 
> document.
> or what is a foolproof way of ensuring that the extend mode is off and that 
> the selection will always include the text I want to copy?
> 
> Thanks 
> 
> Phil
0
Utf
11/25/2009 1:23:04 PM
Reply:

Similar Artilces:

SCR v.s. Documents.OpenEx()
Hi, 1. Reading MSVisio SDK it is a sample how to open e Visio document. Method used Documents.OpenEX(). Results : I open it sucessfully the stencil file but not the document. (It doesn't show up) 2. Reading the article "Programming with MS Office Visio 2003 ActiveX control" it recommands to use axDrawing.SCR property to load a document. Here it works fine for doucments but not for stencil files. Thanks in advanced for any tip. Genc Ymeri. PS: More confusing is that it seems that no one knows how these things are supposed to work. For every question I post the luckest case I g...

Added text to equations
I have a need to add text to a formula that references another cell. Say on one worksheet, I have a column of text from January to December Also, I have worksheets named from January to December. I hav multiple cell references for each worksheet, but they are always th same cell for each worksheet, i.e. January!A1, February!A1, etc. How can I reference these cells without typing in the January! part (o selecting them from each sheet). Ideally, I would like to be able t point to a cell and effectively say add a cell reference to it and hav it return the value of that cell -- AT ----------...

Combo box list selection based on earlier selection by user
HI, I have a form that has a combo box 1 (Product) that reads a the Product table and has a unique id attached to each product (RO#). There is a second combo box 2 that is RO#. Now what I would like to do is when a user selects a Product in combo box 1, the system should lookup the Product selected from combo box 1 and upload the corresponding RO# in the combo box 2 list. Now I am using both combo boxes as Unbound and in the combo box 2 I have the two columns Product and RO# - in the Criteria row of RO# I have the following: Like IIf([Forms]![xa_f_lookup]![RO#]=" ",[Forms]![x...

Run report on multi selected records.
I try to make a report for a custom entity that works like the Account Summary: let's say that it's Customer's Inquiry Summary for entity Customer's Inquiry I made the report so that I'm able to run the report on Customer's Inquiry Form. But when I select multi records in the list of Customer's Inquiry and run report, only one record is show in one page of the the report. I would like to have the selected records appear in the report with each record on each page. How can I do this? ...

Check boxes to text 05-10-10
Is there any way to take information from check boxes that were selected and turn it in to text? I want to have multiple checkboxes to select, and add those selected values to the destription line. ex. checkboxes: red, blue, green Once you have selected, it would add to the header: "Order for lables: red, green" It is not clear what you are trying to do. A check box is simply that - a box which can be checked. If you want to insert some text based upon whether a check box in a protected form is checked, then see http://www.gmayor.com/SelectFile.htm -- <>...

Fast way to search many cells by column for text strings
Am looking for quick way to search for and list, a specified, given text string in all cells in a column, e.g. look for text string " E/G " Assume the target col is col A, data from row2 Put in B2: =ISNUMBER(FIND("E/G",A2)) Put in C2: =ISNUMBER(SEARCH("E/G",A2)) (FIND is case sensitive, SEARCH is not case sensitive) Select B2:C2 and fill down Put a label into B1:C1, then do an autofilter in B1 (or in C1) to filter out the rows with: TRUE, depending on whether search is to be case sensitive or not. -- Rgds Max xl 97 --- GMT+8, 1� 22' N 103� 45' E xd...

Can't select objects in Excel 2007
I'm trying to create a form in Excel 2007, and although I can manipulate, copy & paste controls (check boxes, etc) I can't select multiple objects to align them, etc. I've checked on-line help (and have followed the instructions), and other websites, but no one seems to have indicated a problem. It is extremely cumbersome and I need a solution. Any ideas? Thanks in advance, Jim Berglund I know this is about a year too late, but it may help others who have stumbled across this page looking for similar help. On the Home tab, in the Editing group, click Find & Select....

Lot Selection not Showing when I select PO on Receiving Entry
Usually, the Lot selection screen would pop up when I select a PO at the Line Detail of the Receivings Entry, now it does not! And GP will let items post without a lot number! It seems as if a setting has changed. Any ideas anyone? Any help is appreciated. Thanks, R Are you sure the item is marked to track lots? This wiould be set item by item on the Item Maintenance Options window. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com &q...

Select contact then hangs
Hi, please help. I have a user that when she selects a contact using To: in a new email, after selecting 2, it closes outlook??. Spec is W2kSP4\office2k with all windows updates and office updates installed. Profile has been deleted and re-created, plus i have set up personal folders and moved contacts into there, and set that folder as a default, but makes no difference. Please help. ...

Nudging Text Boxes in a Chart
Has anyone found a way to "nudge" data labels in a PPT chart? I know I can move them by clicking and dragging but when I try to use the arrow keys (as I do for objects) the cursor tabs to other areas in the chart. And when clicking and dragging the labels they seem to snap to a grid and I have very limited control over them. Thanks for any insights!! -- Trisha H No one has to "find a way", there are already several standard ways to accomplish that. :o) Turn off the "Snap Objects to Grid" (in 2003 View, Grid and Guides) or in that same loca...

Selecting rows from various sheets
Hi all, I have several sheets with a few columns in each. One colum in each sheet has a unique value. Most of these unique values are th same in each sheet but not all. Is there any way that I can set up new sheet that will have the unique value in column 1 and th corresponding column values frommeach sheet beside it. For example Sheet 1 aa 1 1 1 bb 2 2 2 cc 3 3 3 Sheet 2 aa 4 4 cc 5 5 Result aa 1 1 1 4 4 bb 2 2 2 cc 3 3 3 5 5 Thanks alot, Sha -- sha ----------------------------------------------------------------------- shav's Profile: http...

numbering text boxes?
Is there a way to number text boxes in a document? I'm trying to create coupons that I can number, putting 3 to a page, so I'd need to number the text boxes rather than the pages. Mail merge... Setup a data base list with numbers. Lots of help here Mail merge http://office.microsoft.com/en-us/publisher/CH010504371033.aspx -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Lisa" <Lisa@discussions.microsoft.com> wrote in message news:5D77331E-3B4A-47B4-BC9B-50FA4E883555@microsoft.com... > Is there a way to nu...

Issue Copying Merged Cell Text
Does anyone know why copying text from a merged cell into another application (ie: the password field of a web site) copies additional blank characters. Is there a way to copy only the actual contents of the merged cell? CinCode5, You can save time when working with merged cells: 1. Get angry first. 2. Don't use them. The second is the option that most folks have come to use. Merged cells cause some problems, and often down the road when you don't suspect they're the cause. -- Earl Kiosterud mvpearl omitthisword at verizon period net --------------------------------------...

Replace text
I have a column of names. On any cell that ENDS with a space followed by a single character (regardless of what it is)I want to remove the space and character. Ex: Williams, Henry B would change to Williams, Henry Hi! =if(mid(A1,len(A1)-1=" "), left(A1,len(A1)-2),A1) Al -- Message posted from http://www.ExcelForum.com Assuming your data in Col A, in cell B1 put the following formula and copy down =IF(ISERROR(SEARCH(" ?",RIGHT(A1,2))),A1,LEFT(A1,LEN(A1)-2)) Then copy the data in Col B, paste special as values over A and delete Col B -- Regards Ken...

select text in Calendar
I'm working on a calendar in Publisher. I'm adding text into a cell by spacing down 1 point, then typing in 8 points. Doing fine until April. At that time, I can only select cells (whole days). It will not let me select the text. Help is no help. Any hints out there. Did I accidentally select something to do this? Bonnie Have you added a picture to the cell or a shape? If you have send it to the back, make the cell no fill and try again. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "GoBonnieGo" <GoB...

macro to filter data based on selected data
Hi, I am looking for a macro that requests input of a reference code and then a date and then filters the data in my spreadsheet based on this criteria. I am using excel 2007. Any help with this will be greatly appreciated. You can probably record a macro while doing it manually and then clean it up and add input boxes to ask the question or input your variable in a cell and use that. If all else fails, If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the ...

Outlook displaying HTML weirdly and attachments as plain text?? Help.
Hi, All of a sudden my SBS 2003 box is passing me emails from people who are sending me email in HTML format but I see it like this: This is a multi-part message in MIME format. ------_=_NextPart_001_01C89B01.1EE51FF9 Content-Type: multipart/alternative; boundary="----_=_NextPart_002_01C89B01.1EE51FF9" ------_=_NextPart_002_01C89B01.1EE51FF9 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Attachments appear like this: ------_=_NextPart_001_01C89B01.1EE51FF9 Content-Type: application/vnd.ms-excel; name="ACCORD 2007-8....

My Documents lockup?
I'm having the strangest problem with my program... I'm using an MFC File Dialog, and if I ever go to the "My Documents" link on the drop-down, my program locks up. I have no problem accessing any other link, Desktop works fine, My Network Places works fine... also, I can navigate to the directory that "My Documents" should be pointing to without difficulty. Can anyone tell me what the problem could be? Thanks Does it happen with other applications as well? Open some office applicaiton or whatever and try to do the same. I bet you see the same behavior. This r...

Link select with a blast
I have Win 7 Home Premium, x64. Quite often, when I select a link, a mouse pointer changes to a palm with a blast. I understand, the palm is the standard mouse pointer for link select, but what is the blast? What it indicates? -- Ilya Zeldes Fort Myers, Florida Hi Ilya, I suspect that this is being caused by a tracking program. Run something like Ad-Aware and see if it indicates a tracking company. If so, you can delete it, however, it might prevent you from accessing that particular website. Dave "Ilya Zeldes" wrote in message news:7A6FF9B1-5512-44...

Select Case in a Change Event
Hi, I am trying to use a worksheet Change Event to trap changes to specific columns. depending on which column is chnaged by the user, the value in another ciolumn will be altered; so, changes in either column O or P will update column Q, changes in either column T or U will update column V and changes in column Z or AA will update column AB. What I can't figure out is the Select Case bit (where I've got the shouted question below). Here's what I've put together, any comments would be much appreciated. Private Sub Worksheet_Change(ByVal Target As Range) ...

Why won't my text shadows show up when I print?
I'm using PPT 2007 and I have placed a drop shadow on some of my text. I can see it in the PPT file and when I view in slide show mode, but when I print to my printer or Acrobat to make a PDF, the shadows don't show up? Any ideas on why this is happening? Go to Office Button | PPT Options and check the option for High Quality Printing. -- Echo [MS PPT MVP] http://www.echosvoice.com What's new in PPT 2010? http://www.echosvoice.com/2010.htm Fixing PowerPoint Annoyances http://tinyurl.com/36grcd PowerPoint 2007 Complete Makeover Kit http://tinyurl.com/32a7nx ...

how to i creat page with text "this page is intended to be blank"
I want to make the page with taxe " this page is intended to be blank" but when I print this page, i want it blank, pls help me and, I have an document with some section, i want some section with setting difference odd and even page in page settup, but it not work, how to do See http://word.mvps.org/FAQs/TblsFldsFms/InsEvnPgEndChap.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Mal" <Mal@discussions.microsoft.com> wrote in message news:F2FFE0A4-7805-43A6-B458-5161DBBF0ABF@microsoft.com....

Select Records based another table...
This may be very elementary, but i can't wrap my brain around it. I have tried to dummy it down as much as i can for myself, with plans of adapting it into something working. I have three tables that look like the following: Tbl 1: ProdID A B C 1 $1 $2 $3 2 $4 $5 $6 3 $7 $8 $9 Tbl 2: RmNum ProdID 1 3 1 2 2 1 2 2 Tbl 3: RmNum Style 1 A 2 C Relationships are: [tbl1 ProdID] ------ [tbl2 ProdID] [tbl2 RmNum] ...

Multi-Select List Box Does Not Retain Selected Items
I created an Outlook Form in 2003. But when I select items in the list box they do not remain select when I select another control on the form. Any suggestions? Did you bind the list box to a keywords field? -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "kaykay" <anonymous@discussions.microsoft.com> wrote in message news:276dd01c4638d$bd5af590$a501280a@phx.gbl... > I created an Outlook Form in 2003. But when I select > items i...

Compare text in 2 different files
I am using Excel 2003 and have two files containing mailing information. I need to check and see which companies are on both lists. I can't use a VLOOKUP formula because some of the company names are slightly different. e.g. One may have a LLC or Inc. at the end and the other doesn't. Is there a formula I can use to compare the first 4 or 5 letters in the company name between the two files? Thanks! Paige Assume you're 2 lists are in A1:A10 and B1:B10 (change to fit your data). Also change the 4 in the LEFT() function to be the number of characters you want to com...