Solved

problems using "MS word" objects form VB5 app

Posted on 1998-02-27
4
290 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
[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
  • 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

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

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

632 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