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
2031 Views

Similar Articles

[PageSpeed] 53

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:

Problems selecting node
Hi, I have the following xml file which is part of a n-level tree: <TREENODES> <TreeNode Text="A1" NodeData="1" NavigateUrl="" ImageUrl=""> <TreeNode Text="A2" NodeData="12" NavigateUrl="" ImageUrl=""></TreeNode> <TreeNode Text="A3" NodeData="13" NavigateUrl="" ImageUrl=""></TreeNode> <TreeNode Text="A22" NodeData="14" NavigateUrl="" ImageUrl=""></TreeNode> ...

How do i insert a page from another publisher document?
I really need to know how i can copy/cut/move/insert a page from another publisher document to the one i am using? Jamie <Jamie@discussions.microsoft.com> was very recently heard to utter: > I really need to know how i can copy/cut/move/insert a page from > another publisher document to the one i am using? In the source document, go to the page you want. Deselect all objects. Ctrl+A, Ctrl+C. In the destination document, insert a new blank page. Ctrl+V. -- Ed Bennett - MVP Microsoft Publisher ...

help for sql select command !!!
Hi Everyone! Imagine we have 3 checkBoxes in a search page and 3 boolean fields in DB table and every checkbox is for one of these fields . In search page users check every 3 checkBoxes and what i want is that first it shows the records that every their 3 fields are checked then 2 and then 1(DESC). BTW my DB is MS Access. Please help me ! On Mar 1, 7:17=A0pm, "miladha...@gmail.com" <miladha...@gmail.com> wrote: > Hi Everyone! > Imagine we have 3 checkBoxes in a search page and 3 boolean fields in > DB table and every checkbox is for one of these fields . I...

How do I add a hyperlink to specific location in another document 04-14-10
I have two word documents. I want to jump from one document to a specific location in the other document. I can jump to the other document, but haven't figured a way to make it go to the bookmark I want it to. For example, I have a hyperlink in Document 1. I want that hyperlink to take me to Chapter 4 of Document 2. In Document 2, I have a bookmark named Chapter4. According to the field code help for HYPERLINK, you can add a switch for location (/l), but I have not figured out how to properly format it so that it works. Any help is appreciated. Thanks. ...

text display in MDI
Hello Friends Iam niranjan Developing MDI Application in vc++6.0 when iam displaying text in windows iam using OnDraw and OnChar functions. in OnChar function iam incrementing the x,y positions accoording to Key strokes. and making the string buffer to empty in "Enter" Key stroke in OnDraw function by using pDC->TextOut(x,y,str) iam displaying the text here iam not getting the proper data.... my problems are.... 1. after giving ther enter key curson going to next line but previous lines data in erasing , after ever enter key.. if any one knows solution plz help me to get th...

text in a vertical column
I am trying to get a word in a coulum without having to enter each letter with a return after. In article <FA7EDA2C-5B2C-4F96-A1E3-EA6EA2913A10@microsoft.com>, Jabiru wrote: > I am trying to get a word in a coulum without having to enter each letter > with a return after. ... in what program? ...

reporting document amount
I have the following SQL working in SQL Reporting Services, however I need to also add in the document amount (amount of check). This data is stored on the Payables Payments Zoom screen. I just need to know the name of the underlying table and field name that stores this information. Thanks!! select CompanyID, DOCNUMBR, Checks.DOCNUMBR CheckNumber, Checks.CHEKBKID , DOCDATE CheckDate, Vendor.VENDORID, VENDNAME, VNDCHKNM,ADDRESS1, CITY, STATE, ZIPCODE, PHNUMBR1,USERDEF1, PT_UD_Key PaymentID, DATE1 CheckDeliveryDate from ECFCA.dbo.PM00400 Checks join ECFCA.dbo.PM00200 Vendor on Vendor...

Open hidden sheets from a drop down list selection
I have a file with many hidden sheets eg Sheet1, Sheet2...Sheet50. What I want is some code which looks at the selection from a drop down list (on a visible sheet) and the open that sheet. ie if I select Sheet5 from the drop down list, Sheet5 becomes visible. I then want to hide it again once I have finished with it (I can do that bit!). The reason I am doing this is because otherwise I will have too many sheets to tab through. Any thoughts? Ant Manually you can leave the sheets unhidden but right-click on the sheet navigation buttons at bottom left to get a 15 name list of sheets with...

Select record in a listbox
Hello John W. Vinson helped me with a code to search records in a Table to show in lsbAut Private Sub CmdA_Click() Dim strSQL As String Dim db As DAO.Database Dim rs As DAO.Recordset strSQL = "SELECT AuID, AutName FROM TAut WHERE AutName LIKE 'A*' _ & " ORDER BY AutName;" Set db = CurrentDb Set rs = db.OpenRecordset(strSQL) If rs.RecordCount > 0 Then Me!lsbAut.RowSource = strSQL Else MsgBox "No records in DB" End If rs.Close Set rs = Nothing End Sub Now I would like to do is: 1. In lsbAut select a record by Aut...

Accessing a linked file in a Word document using VBA
Hi - Basic question, in my Word template I have some linked images. I want to use VBA to change the path and filename of some of these links ... can anyone give me a clue as to how I should best do this? Thanks Robin Hi Robin, To see how to paths in Word using vba, check out the macro solution I've posted for implement relative paths at: http://lounge.windowssecrets.com/index.php?showtopic=670027 -- Cheers macropod [Microsoft MVP - Word] "Robin" <Robin@discussions.microsoft.com> wrote in message news:7EA2C548-7D01-4515-BCC8-2EF3210439C9@microsof...

Opening new document in Excel
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel I just switched from PC to MacBookPro with Microsoft Office 2008. It seems puzzling that when I open Excel to begin a new workbook there seems to be multiple sheets already open. Is there a way to only one sheet open when starting a new document? <br> Thank you. Three sheets is the default number for Mac as well as PC versions of Excel [although I'm not 100% sure about 2007, but I believe it's the same). You can change the default in Excel> Preferences - General. Pick a number from 1-2...

Cannot select text with shift key
Hi! I have a pretty annoying problem with Outlook 2007 SP1. When I write some text and directly tries to select the text I've written with the shift and arrow key it will not select the text. I can easily reproduce the error by doing the following steps: 1. Open a new mail 2. Tab down to the text area 3. Write "hello" 4. Hit Shift+Left Arrow The expected result would be to select the "o" in the written text, but the actual result is that the letter is not selected. It is the same problem with Ctrl+Shift+Left or Shift+Home. I run it on Windows Vista x64 SP1. When I t...

Need help re-installing Money 2007 with minimal documentation avai
My PC experienced a power failure while defragging my hard drive, and now, when I try and start Money 2007 I'm greeted with "Money was unable to load the registration library" and the program exits. I'd like to re-install Money, but have run into several roadblocks Since it won't run, I can't get my order information (SKU ?) to complete the installation process at DigitalRiver. The "order ID" on the Money cd (dated Saturday 10 February 2007) is apparently not the same as the information needed at Digital River. Where do I go from here??? Thanks...

selecting cells #3
When working with a large group of cells, I find it easier to click the top cell, scroll to the bottom, and click the last cell while holding the shift key down. The problem is, when I want to select a second column of data, I have to select the top cell using the control key, the pull down the cursor manually. Is there a way to select 2 or more non-adjacent columns without having to scroll down using the mouse? Nevermind - figured it out myself. The easiest things are often so obvious they are hard to see. "Wazooli" wrote: > When working with a large group of cells, I...

Sorting "text" numbers
I am sorting a list of numbers (actually telephone extensions) which need to be formatted as text. When I sort them I get two separate lists starting over again. e.g. 1000,1001,1004,2003,3456,...,0456,1003,2455,... I've check for leading spaces, format differences etc. but this is not the problem. Chris, If the cells were formatted after entering the data, the currently entered values aren't automatically converted from numbers to strings. Do your sort, then select the first group of cells and run this macro: Sub MakeText() For Each myCell In Selection myCell.Value = &q...

Cells containing lots of text will not wrap?
Hi, I have a report to complete on an excel sheet. Some of the cells contain lots of text and no matter how I format the cell I can't get it to show me all of the text. It behaves fine up to a certain point, line wrapping as it should but then it reaches a point where the text just disappears from view. It's still there in the cell but just not visible. Manually increasing the size of the cell has no effect. This is driving me nuts! -- Regards Jon If you add alt-enters to force new lines within the cell (every 80-100 characters), then you'll be able to see more characters...

Create Auto Text in Excel?
I want to be able to add the following function (=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename ",A1),1))) into any excel sheet that I'm working on like you can do in Word with Auto Text insert. I think I should be able to do this with a macro but I can't figure out how to do it. Any help much appreciated. Cheers Lee First, you can shorten the formula a bit and reduce the number of function calls by using =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,32) XL doesn&...

Saving as a csv file with text qualifiers
I have the following three values in 3 cells a1 b1 c1 adam john lilly I want to export this into a csv file that should look like this: "adam","john","lilly" How do I do it? Thanks in advance for the help One way: http://www.mcgimpsey.com/excel/textfiles.html#csvwithquotes In article <33b0685e.0501180614.1a04ff40@posting.google.com>, rs.pai@sbi.co.in (Rajendra Pai) wrote: > I have the following three values in 3 cells > > a1 b1 c1 > adam john lilly > > I want to export this into a csv file that should look like th...

Individual formatting on a text box on a report w/tabular layou?
Hyall, I can change the background color of the detail in a report with tabular layout (that is, similar to a continuous form) using Detail_Format: Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) With Me Select Case .txtCondition Case "Green" .Section("Detail").BackColor = vbWhite Case "Yellow" .Section("Detail").BackColor = vbYellow Case "Red" .Section("Detail").BackColor = vbRed End Select End With End Su...

Visio thinks an invisible line is present during line routing, but can't select it otherwise
I spent hours making a big flow chart only to notice when I'd finished that Visio thinks that there is an invisible long line that extends vertically up about 3/4 of the chart. At least I think that's what Visio thinks. The line is invisible so it is somewhat hard to see. The only reason I know it's there is because all of the lines that cross it have that little cross over hump in them. How can I get rid of this invisible line? -- Richard Lewis Haggard It may be an invisible line or it may be an alignment bounding box that is way too big. If the drawing doesn't ha...

why is an apostrophe in front of text
After entering a text in a cell or in the function field, when i go back in the cell an apostrophe apear in front of the text. How can i correct this? Thank you Try: Tools|Options|transition tab Uncheck "transition navigation keys" I've unchecked all those Lotus 123 transition settings. If you need them, don't do it. But if you're like most excel users, I'd uncheck them. mlu wrote: > > After entering a text in a cell or in the function field, when i go back in > the cell an apostrophe apear in front of the text. > > How can i correct this? &g...

Text box in master document moves out of print range
I have placed a text box at the bottom of the master page using publisher 2003. I have set it to be compatible with all my printers. However, when I set the print option to greyscale it shifts the box to a position lower than any printer can handle. It often looks ok in preview, but not on the hard copy itself. I have also noticed that the text moves in some cases witht he help of additional tabs. Why is this. My document is 200 pages long with 15 chapters. I have to change each chapter 4 times (left & right pages masters A & B) to overcome this problem. Your help would be much ...

imbed excel cell text in a shape
I need to insert a number into a shape that corresponds to a cell in excel. Kinda like the exploded parts view in a car repair manual. A callout shape with a text value "123" that is linked to cell A1 in file ***.xls. It would be nice to be able to auto generate the callouts from the excel file. shape 123 is cell A1, shape 124 is cell A2 and so on. Thanks what version of visio are you running? al "mystified" <mystified@discussions.microsoft.com> wrote in message news:80B4E390-190A-41D9-AC4A-F96C1DA6FB6E@microsoft.com... >I need to insert a number into a s...

Editing a shared document that has some read-only capabiities
We have an excel document where all of the columns, except for three, have been locked down. We password protected the spreadsheet and then shared it. Most cells are read only, but there are places that certain users need to click and type into. Somehow the columns that were unlocked have become read only. As I am the only one with a password and I have not opened the document I'm not sure how this happened... This type of scenario where a document needs to be shared but the integrity of the data needs to remain occurs often and I've run out of Excel tricks. How can ...

CFileDialog hangs on "My Documents" click
Platform: Windows 2000 Internet Explorer: 6.0 All patches applied from Microsoft. The following code works fine in our multithread applications, except one thing. When the user clicks on the "My Documents" icon, the program hangs. The rest of the icons work fine. We have tried different machines and have gotten the same results. If we try the application on a Windows XP platform, the error goes away. Anybody got an idea on what the problem might be? static char BASED_CODE szFilter[] = "Ascot 5 Exercise Files (*.aef)|*.aef|Ascot 4 Exercise Files (*.exr)|*.exr|All Fil...