Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Accessing a word document

Posted on 2000-04-20
10
Medium Priority
?
258 Views
Last Modified: 2010-05-02
This is what I want to do...

I made a web site in ASP where users can log on and transmit information, which used to be in a Word Document.  I need to make a VB program to

1. Open a word document
2. Get the information needed
3. Submit it to a SQL database

I assume that the submitting of information is virtually the same as what is done in VBScript, which could probably be easily found on the internet somewhere, but what is the code to open a word document and then atleast get me started on searching the document for key fields?

Thanks
thunderchicken
0
Comment
Question by:thunderchicken
[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
  • 6
  • 3
10 Comments
 
LVL 1

Expert Comment

by:Gotcha007
ID: 2735003
Go to the ProjectMenu choose Reference  and add a reference to Microsoft Word 8 object library.


Create a class module with the Name =  EventClassModule and put this code inside:

Public WithEvents AppWord As Word.Application

Private Sub Class_Initialize()

   'Instantiate a new instance of Word and add
   'a new document
   Set AppWord = New Word.Application
End Sub



in your form :

Set X = New EventClassModule
X.AppWord.Documents.Open "c:\Mydoc.doc"

for any help using This object you can go to the word help and choose VB Chapter.


Ludo


0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2735012
thunderchicken:

Private Sub Command1_Click()
    On Error GoTo errWordNotOpen
    Dim appWord As Word.Application
    Dim docWord As Word.Document
    Dim rngWord As Word.Range
    Set appWord = GetObject(, "Word.Application")
    If appWord Is Nothing Then
        Set appWord = CreateObject("Word.Application")
    End If
    appWord.Visible = True
    Set docWord = appWord.Documents.Open("<full path to document>")
    ' Code for finding fields etc.,
    docWord.Close
    Set docWord = Nothing
    appWord.Quit
    Set appWord = Nothing
    Exit Sub
   
errWordNotOpen:
    If Err.Number = 429 Then
        Resume Next
    Else
        MsgBox Err.Description & vbLf & CStr(Err.Number), vbCritical
    End If
End Sub

Will get you started by opening a word document, you then need to find the appropriate fields in the document. Depending on what you are looking for and how the document is formatted there may be many ways to do this.
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 2735111
On both codes, I get the "User-defined type not defined" error.  I have only wrote "basic" BASIC programs and have not really gotten deep into these aspects, can either of you write out step by step what I need to do to atleast be able to access the file?  Right now I have a file1 and drive1 so the user can search for the file, then click a button, from there all I need to do is have the program search the document, since the format will be the same it will be easy to give error messages, and with that I can directly take out the data I need, since the word document is set up and users just click on where to get the data.  Any additional help is helpful!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 43

Expert Comment

by:TimCottee
ID: 2746552
gotcha007 made the point that you need to add a reference to Word automation objects to the project.

On the "Project" menu, choose "References", scroll down until you see something like:

"Microsoft Word 8.0 Object Library"

check the box next to this. This will add references to the OLE automation objects within word to the project, the undefined type errors should then disappear.

It would help if you could give some more information as to how the documents are set out, if for example there are bookmarks in the document which can be used to navigate through, or whether the information you want is at specific points in the text. If so how to identify which portions of the content to return.
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 2747254
okay, i'll check it out today, thanks
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 2748419
Thanks Tim, I used your code, but one last question and I'll give you the points, can you give me direction on how to start to open the file and sort the information?  Maybe a key would be in the field Name: on page 2 and I'll need the name after that.  Just an example, there are about 2000 that I need, but it will get me started.  Thanks in advance
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 2748427
or split the points, whoever can help me out first
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 400 total points
ID: 2750628
thunderchicken, here is a start, replace "code for finding fields" with:

    Set rngWord = docWord.GoTo(What:=wdPage, Which:=wdGoToAbsolute, Count:=2)
    With rngWord.Find
        .Execute "Telxon", True, True
        MsgBox .Found & vbLf & rngWord.Start & vbLf & rngWord.End
        rngWord.EndOf Unit:=wdParagraph, Extend:=wdExtend
        MsgBox rngWord.Text
        rngWord.Bold = True
        rngWord.Font.Size = 72
    End With

The first line sets a range starting at the beginning of page 2. Finds the word Telxon, extends the range to the end of the paragraph, then sets the text in this range to bold & size 72 points.

It should help to give you an idea of how to find bits of the document and manipulate the formatting. The help is a bit awkward sometimes to understand but does have everything you need.
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 2751130
Thanks for your help, that will get me started on the task.
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 2766561
http://www1.experts-exchange.com/bin/Q.10334457

150 more points if interested
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

609 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