?
Solved

vb left function not working

Posted on 2008-06-10
2
Medium Priority
?
350 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
[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 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Technology Partners: 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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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