Solved

Text from Word to Access

Posted on 1998-10-24
7
215 Views
Last Modified: 2012-08-14
I have a Word document that is a list of contracts; each starts with the same string, so the beginning of each is identifiable.  I want to select the text following this string, copy it to a new record in an access table, then move to the next item, copy it, and so on.  The question is how to select the text; the VBA documentation is confusing. Do I bookmark the occurrences of the string, then somehow select between bookmarks?  I dont know how to think about this, really.
0
Comment
Question by:jackwalsh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

by:david_levine
ID: 1614156
Is this a one-time thing (populate Access) or something you want to do on an ongoing basis?
0
 

Author Comment

by:jackwalsh
ID: 1614157
I want to do this on an ongoing basis--that is, I want to have a form in access with a command button that is pushed, opens Word, opens the file (which I receive daily), selects the correct sections of the text, copies each one to a new record in an access table, closes Word, and then distributes the text to selected email addresses.  I've got it all working except the ability to select the text, copy it, then select the next chunk.
So close!  
The problem is that I don't understand how to make a range from the current cursor position to the next occurrence of a string; once I get that, I'm ok.  The examples all show extending a range by a paragraph, or a sentence, or a word, or some object, rather than to a particular bit of text. Somehow it appears that bookmarks can be used, but the documentation of bookmarks is confusing--they are both objects and properties, I think, but I don't really understand.  Thanks for your help

Jack Walsh
0
 
LVL 3

Accepted Solution

by:
frazer earned 100 total points
ID: 1614158
Hi,

you should use Find to do the work for you.  It will select the text you are searching for....

With Selection.Find
        .Text = "REM"
        .Forward = True
        .MatchCase = True
        .MatchWholeWord = True
End With


then use

Selection.Copy

and then paste it into Access

To find the next occurance use...

Selection.Find.Execute


Put all this code into a loop to search the whole document.

Hope this helps

Frazer
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 3

Expert Comment

by:frazer
ID: 1614159
Hi,

Sorry I didn't read your question properly, try this code it should do more what you want


Sub WordSelecting()
    Dim temp As Range
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "REM"
        .Forward = True
        .MatchCase = True
        .MatchWholeWord = True
    End With
    Selection.Find.Execute
    Set temp = ActiveDocument.Range(Start:=Selection.Range.Start + Len(Selection.Find.Text), _
    End:=Selection.Range.Start + 16)
    Debug.Print Trim(temp.Text)
End Sub


hope this helps

Frazer
0
 

Author Comment

by:jackwalsh
ID: 1614160
Almost, not quite.  What I have is a standard heading for each sections of text---call it XXXXX.  What I want to do is select the text between the first occurrence of XXXXX and the second occurrence of XXXXX, copy it to an access record, then select the text between the second occurrence of XXXXX and the third, copy it, then between the third and fourth, and so on. The problem is that the text is of variable lengths; I can't just find XXXXX and go six paragraphs, or something like that.  It has to go from one occurrence to the next.  The problems is in finding the end of the selection.  Does this need bookmarks at each occurrence, then select from bookmark to bookmark?
0
 
LVL 3

Expert Comment

by:frazer
ID: 1614161
Hi,

Now I understand, this should work ok now....

Sub WordSelecting()
    Dim temp As Range
    Dim wdStart As Long
    Dim wdEnd As Long
    ActiveDocument.Range(1, 1).Select
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "REM"
        .Forward = True
        .MatchCase = True
        .MatchWholeWord = True
    End With
    Selection.Find.Execute
    wdStart = Selection.Range.End
    Do While Selection.Find.Execute = True
        wdEnd = Selection.Range.Start
        Set temp = ActiveDocument.Range(Start:=wdStart, End:=wdEnd)
        Debug.Print Trim(temp.Text)
        wdStart = Selection.Range.End
    Loop
End Sub


Hope this helps

Frazer
0
 

Author Comment

by:jackwalsh
ID: 1614162
Wonderful!  Frazer stuck with it until he made me state the problems in a way it could be understood.  Many thanks!!
0

Featured Post

To Patch or not to Patch? That is the question!

Don't get caught out like thousands of others around the world in the recent Ransomware Fiasco!
Discuss..
- Why it's not a good idea to wait before Patching
- Sensible approaches to Patching discussed
- Add your feedback, comments and suggestions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Auto save MS Word - shortest intervals 10 24
Way to transfer 29 62
Excel + CountIfs + two colums 5 37
Vlookup (Microsoft Excel Programming) 5 26
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question