The "After cell" MUST fall within the search range....you have specified a
value outside the range.
The find method takes 8 arguments, you provide only 6.
This worked for me:
(setq myRow (xlm-find myRange ;Where to search
hgt ;String to search for
nil ;After cell
xlc-xlvalues ;Check values
xlc-xlwhole ;match whole or part
nil
nil
nil
nil
)
)
wrote in message news:5370521@discussion.autodesk.com...
I have a Visual LSIP program to find a specific value in Excel. I'm able to
open the excel file and point to a specific range. However, I cannot get the
"find" method to work. It always gives me the following error:
"Automation Error - Description not provided"
See the program below.
All variables in the program are assigned a value until it gets to the myRow
variable. The program fails at this point.
Does anyone have any ideas how I can get this to work. Much of the program
was pasted over from some other examples I've found on the internet.
(defun c:extest ()
(vl-load-com)
(setq sheetName "OUTSIDE WALL"
hgt "93")
;;;--- Get the system drive
(setq sysDrive (getenv "systemdrive"))
;;;--- If the excel object library is not found...load it
(if (null Library)
(progn
;;;--- Find out which version we should use
(setq Library
(cond
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office\\Excel8.olb")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office\\Excel9.olb")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office\\Excel10.olb")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office\\Excel.exe")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office10\\Excel.exe")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office11\\Excel.exe")))
((findfile (strcat sysDrive "\\Program Files\\Microsoft
Office\\Office11\\XL5EN32.OLB")))
)
)
;;;--- If the library was found...
(if Library
(progn
;;;--- Strip off
(setq LibVer (substr (vl-filename-base Library) 6))
(cond
((= LibVer "8")(princ "\n Opening Excel Version 8..."))
((= LibVer "9")(princ "\n Opening Excel Version 9..."))
((= LibVer "1")(princ "\n Opening Excel Version 10..."))
((= LibVer "") (princ "\n Opening Excel Version 2000+..."))
((= LibVer "3")(princ "\n Opening Excel Version 2003..."))
)
(vlax-import-type-library
:tlb-filename Library
:methods-prefix "XLM-"
:properties-prefix "XLP-"
:constants-prefix "XLC-"
)
)
(alert "Excel Object Library was not found!\n\nLook inside the
XL_Readme.txt file for HELP.")
)
)
)
;;;--- If an excel application is not loaded, proceed...
(if (null myApp)
(progn
;;;- Select an Excel workbook
(setq fileName "c:/cad/support/tafco/shear sizes/shear sizes.xls")
;;;--- Verify the path to the file
(setq fileName(findfile fileName))
;;;--- Set the default file name globally for next use
(setq oldFileName fileName)
(princ "\n Opening Excel file...")
;;;--- If Excel...
(if(setq myapp(vlax-get-or-create-object "Excel.Application"))
(progn
;;;--- Open the workbook
(vlax-invoke-method (vlax-get-property myapp 'WorkBooks) 'Open
fileName)
;;;--- Set it to invisible mode
(vla-put-visible myApp 1)
;;;--- Get the workbooks object
(setq myWBooks(vlax-get myApp "Workbooks"))
;;;--- Open the excel file
(setq myWBook(vla-open myWBooks fileName))
;;;;--- Get the sheets object
(setq mySheets(vlax-get myWBook "Sheets"))
;;;--- Get the selected worksheet
(setq mySht(vlax-get-property mySheets 'Item sheetName))
;;;--- Make the selected worksheet active
(vlax-invoke-method mysht "Activate")
(setq myRange (xlp-get-range mysht "B4:B100"))
(setq aftRange (xlp-get-range mysht "B3"))
;;Search 1st column
;;
;; Use FIND method of Excel with defaults
;;
(setq myRow (xlm-find myRange ;Where to search
hgt ;String to search for
aftRange ;After cell
xlc-xlvalues ;Check values
xlc-xlwhole ;match whole or part
nil
nil
)
)
)
)
)
)
(cond
(
(not(vlax-object-released-p myApp))
(vlax-invoke-method myApp 'QUIT)
(vlax-release-object myApp)
)
)
);end function