Solved

problems using "MS word" objects form VB5 app

Posted on 1998-02-27
4
285 Views
Last Modified: 2008-03-10
I am writing a VB app which create/manipulates a word 97 document. I have successfully been able to use the "createobject" function to insert text into a new word document. Now I need to search the document and replace certain words, but the "find" method does not work for me. I also cannot seem to use the "activedocument" object without an error. I have done the following:

     Dim word as object
     Set word = CreateObject("word.application")

    ' Make word visible through the Application object
    word.Application.Visible = True
    word.Documents.Open "C:\test.doc"
     
    If Option1(0).Value = True Then
        word.Application.selection.InsertFile filename:= mypath & "new.doc", Link:=True


*Here is where things don't work*
With word.selection.Find
        .clearformatting
        .Text = "something"
        .Replacement.clearformatting
        .Replacement.Text = myform.Text1.Text
        .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
    End With
0
Comment
Question by:englm
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
anthonyc earned 100 total points
ID: 1458066
Take a look at 3 things:

1) Make sure you have a reference in your project to the word library.  If you don't, the constants you are using will not work (wdReplaceAll and wdFindContinue will not be there correct values)

2)  Replace .replacement.text = myform.text1.text with
            .replacement.text = trim$(myform.text1.text) 'explicit conversion to text

3)  Try without the WITH statement.  Some objects do not work correctly with it.  For example, the LINE method of a picturebox does not work will with the WITH statement
0
 

Author Comment

by:englm
ID: 1458067
In your answer:

1) Make sure you have a reference in your project to the word library.  If you don't, the constants you are                   using will not work (wdReplaceAll and wdFindContinue will not be there correct values)

Question:

1. What is the reference that needs to be selected for the word library? Is it the VBA reference?



0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1458068
Word 97 Object Library ( I dont have word 97, so check to see if this exists) and if not, Office 97 object library or Word 8 object lib or Office 8 object lib.
0
 

Author Comment

by:englm
ID: 1458069
I tried the Word 8 lib and it worked so far. Thanks.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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