Author Topic: Word.Application Object  (Read 1912 times)

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
Word.Application Object
« on: May 23, 2005, 12:13:28 PM »
Using Visual Lisp is there any way to determine if a particular Type Library is already loaded.  I use this to load the Type Library for Word, but if it is already loaded I get an error that says the protected symbol is already used.  Any ideas?



Code: [Select]
(defun typeLib_word (/ sysdrv)
  (setq sysdrv (getenv "systemdrive"))
  (vl-remove
    nil
    (mapcar
      '(lambda (x) (findfile (strcat sysdrv x)))
      (list "\\Program Files\\Microsoft Office\\Office\\MSWord8.OLB"
   "\\Program Files\\Microsoft Office\\Office\\MSWord9.OLB"
   "\\Program Files\\Microsoft Office\\Office10\\MSWord.OLB"
   "\\Program Files\\Microsoft Office\\Office11\\MSWord.OLB"
      )
    )
  )
)
;;;
(defun load_typelib_word (/ tlb_file tlb_ver)
  (and (setq tlb_file (car (typeLib_word)))
       (vlax-import-type-library
:tlb-filename    tlb_file
:methods-prefix    "msw-"
:properties-prefix "msw-"
:constants-prefix  "msw-"
)
  )
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
Word.Application Object
« Reply #1 on: May 23, 2005, 12:41:33 PM »
2 options:

Turn off error warnings in the vlide
Check for a NON-NIL value for msw-Accept ...

Option 1:

Under the general options of the VLIDE, set error noitification to transparent

Option 2:
Code: [Select]

(if (not msw-Accept)
 (load_typelib_word)
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

whdjr

  • Guest
Word.Application Object
« Reply #2 on: May 23, 2005, 02:07:24 PM »
Thanks for the reply Keith, but is there a bigger issue than just vlide error warnings?
What I mean is that if you keep hitting no, it prompts with another message.



I have to shut down Autocad or bypass the portion of code that loads the type library before it will stop giving me error messages.  That's the reason I was wondering if I could test to see if the type library could already be accessed from Vlisp, kinda like vl-catch-all-error-p determines if an argument is an error.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
Word.Application Object
« Reply #3 on: May 23, 2005, 02:40:17 PM »
Quote from: whdjr
Thanks for the reply Keith, but is there a bigger issue than just vlide error warnings?


Actually that IS the issue ...

The VLIDE automatically prompts the user (using default settings) whenever any code attempts to set a value to a "protected" variable .. which ALL of the variable functions are when you load a type library ...
The VLIDE is doing EXACTLY what it should do... prompting you because your code is attempting to set a variable to a protected variable.


Quote from: whdjr
What I mean is that if you keep hitting no, it prompts with another message.

I have to shut down Autocad or bypass the portion of code that loads the type library before it will stop giving me error messages.


That is by design in the VLIDE ....

Quote from: whdjr
That's the reason I was wondering if I could test to see if the type library could already be accessed from Vlisp, kinda like vl-catch-all-error-p determines if an argument is an error.


This is not a lisp generated error, it is a VLIDE generated error. To intercept this error you would need to be able to control the VLIDE ... a much simpler solution is to set all of these errors to "transparent" in the VLIDE as I posted earlier, or to prevent them from ever happening, use the code I posted above ....

Essentially what happens is it checks to see if a single variable has already been set, if it has, then it is obvious that the type library has been loaded. If it is not, the it has not been loaded and you can load it without problem.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

whdjr

  • Guest
Word.Application Object
« Reply #4 on: May 23, 2005, 03:34:36 PM »
AAAHHHHHH!!!!!!

I see said the blind man. 8)

Jürg Menzi

  • Swamp Rat
  • Posts: 597
  • Oberegg, Switzerland
Word.Application Object
« Reply #5 on: May 24, 2005, 02:12:33 AM »
There is another point also you've to consider. Methods, properties or constants may have the same name. Vlisp isn't able to seperate those things. So you've to add an appropriate prefix (Excel sample):
Code: [Select]
  (if (null excc-xl24HourClock)
    (vlax-Import-Type-Library
     :tlb-filename ExcTlb
     :methods-prefix "excm-"
     :properties-prefix "excp-"
     :constants-prefix "excc-"
    )
   )
Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k14... A2k18 - Start R2.18

StarGazer

  • Guest
Word.Application Object
« Reply #6 on: May 24, 2005, 09:24:40 AM »
Hi People,
 is there a tutorial on how to get office stuff to work with vlisp? I'm very new to this type of programming. I'm a simple "draw a line" programmer.  :oops:

thanks
Thomas

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
Word.Application Object
« Reply #7 on: May 24, 2005, 10:24:07 AM »
Quote from: Jürg Menzi
There is another point also you've to consider. Methods, properties or constants may have the same name. Vlisp isn't able to seperate those things. So you've to add an appropriate prefix (Excel sample):
Code: [Select]
  (if (null excc-xl24HourClock)
    (vlax-Import-Type-Library
     :tlb-filename ExcTlb
     :methods-prefix "excm-"
     :properties-prefix "excp-"
     :constants-prefix "excc-"
    )
   )
Cheers


Thanks for clarifying that issue, however, you should note that in Will's original code, he does indeed add a prefix to designate the MicroSoftWord type library.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Jürg Menzi

  • Swamp Rat
  • Posts: 597
  • Oberegg, Switzerland
Word.Application Object
« Reply #8 on: May 24, 2005, 11:07:09 AM »
Quote from: Keith
Thanks for clarifying that issue, however, you should note that in Will's original code, he does indeed add a prefix to designate the MicroSoftWord type library.

Im aware of that...
But methods, properties or constants probably can have the same names inside Word or whatever.

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k14... A2k18 - Start R2.18