Solved

vb left function not working

Posted on 2008-06-10
2
340 Views
Last Modified: 2012-06-21
hi,
i have vb sub under Excel, which returns this error: "Object doesnt support this property or method".
the code succesfully openes a word doc file, and cycles through each word in the doc.
i want to write a line saying: "if a word starts with the letters FLD then..."
but i keep getting this error message.
i tried using left and left$ (i dont know the difference but i saw the use of both), but both didnt work.
the code attached. can anyone tell me what i'm doing wrong?
thanks!
Private Sub OK_Click()

'hide form

findProposal.Hide

Dim path$

'gets the path for the word file

path$ = findProposal.Label1

GetWordDoc (path$)

End Sub
 

Function GetWordDoc(strPath As String) As Boolean

   Dim objDoc As Object, objRange As Object, objAppWord As Object

   Dim strNewPath As String

   Dim wks As Worksheet

   Dim n As Long

   Dim varLookup

   On Error GoTo err_handle

   GetWordDoc = True

   Set wks = ActiveWorkbook.Sheets("MergeSheet")

   Set objDoc = GetObject(strPath, "Word.Document")

   Set objAppWord = objDoc.Application

      

   For n = 1 To objDoc.Words.Count

'this is the problematic line:

       If Left(objDoc.Words.Text, 3) = "FLD" Then

       End If

nextn:

    Next n

     

clean_up:

    objDoc.Close

   Exit Function

err_handle:

   MsgBox Err.Description

   GetWordDoc = False

   Resume clean_up

End Function

Open in new window

0
Comment
Question by:Or_A
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21749762
change:
For n = 1 To objDoc.Words.Count
'this is the problematic line:
       If Left(objDoc.Words.Text, 3) = "FLD" Then
       End If
nextn:
    Next n

into:

For n = 1 To objDoc.Words.Count
'this is the problematic line:
       If Left(objDoc.Words(n).Text, 3) = "FLD" Then
       End If
nextn:
    Next n
0
 

Author Closing Comment

by:Or_A
ID: 31465669
i'm dumb
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now