Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

problems using "MS word" objects form VB5 app

Posted on 1998-02-27
4
Medium Priority
?
293 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

877 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