TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on March 01, 2013, 10:25:35 AM
-
is it possible?
any tutorials?
any examples I can learn from?
thanks
-
It would be similar to reading Excel files. I.e. you link to Word through ActiveX and open or use an already opened document. From there you'll need to figure out how the Word ActiveX library works - do some googling on Word VBA.
-
ive been googling it for a couple days before i asked here
i dont know what vba code to look for
and anything lisp wise for this is limited.
i was hoping maybe someone here had a link or a tutorial or example code they would be willing to share so i could learn.
ill keep searching
-
See what this does:
The .12 portion of the string may be different depending on the version of Office you have installed.
-
See what this does:
The .12 portion of the string may be different depending on the version of Office you have installed.
lol here is what is returned.. ill have to go thru this a little at a time but maybe someone else could use the info
-
This might be a little more help. See if you can pick this apart :-)
(defun c:test (/ doc docs result wa words)
(and (setq wa (vlax-get-or-create-object "Word.Application"))
(setq docs (vlax-get wa 'documents))
(setq doc (vlax-invoke docs 'open "C:\\test.docx"))
(setq words (vlax-get doc 'paragraphs))
(vlax-for word words (setq result (cons (vlax-get (vlax-get word 'range) 'text) result)))
(foreach line (reverse result) (alert line))
)
)
-
thanks Ronjob, this is good learning code for me
one thing, i cant open the file now.
i need to close it but
(vla-close Docs) doesnt work whats missing?
-
oopps never mind its closed.. dunno what that was about tho..
-
You can use (vlax-invoke doc 'close) to close :-)
-
this is excellent
thanks again, sir
-
Glad to help 8-)
-
Be careful to release the Word Application object when operations have finished, and to also include the required error trapping to ensure that this object is safely released should an error occur whilst interfacing with the word document.
Also, you will need to use the Quit method of the Application object to close the Word Application before releasing the object, otherwise the winword.exe process will remain active with no possible way to access the application without terminating the process manually using the Task Manager.
In short, it is good programming practice to clean up after yourself :-)
-
Be careful to release the Word Application object when operations have finished, and to also include the required error trapping to ensure that this object is safely released should an error occur whilst interfacing with the word document.
Also, you will need to use the Quit method of the Application object to close the Word Application before releasing the object, otherwise the winword.exe process will remain active with no possible way to access the application without terminating the process manually using the Task Manager.
In short, it is good programming practice to clean up after yourself :-)
thats funny i was just going to ask this.
i notice in an excel function it says this for error handling
would this be the same but with my variables?
(defun *error* (msg)
(and msg
(/= msg "Function Canceled")
(princ (strcat "\nError: " msg))
)
(and wBook (vlax-invoke-method wBook 'Close :vlax-False))
(and xlApp (vlax-invoke-method xlApp 'Quit))
(and reg (vlax-release-object reg))
(mapcar (function (lambda (obj) (and obj (vlax-release-object obj))))
(list rng wBook xlApp)
)
(gc)
)
also the doc file opens and closes after running the code
i tried
(vla-put-visible doc :vlax-false)
but that doesnt work, whats the equivalent of this?
or how do stop the doc from popping up and closing?
where should i be looking for the vlax functions?
-
To hide Word try using (vlax-put wa 'visible 0).
-
how can i get the header and footer info?
-
Error: bad list: "this is a test\r"ActiveX Server returned an
error: The object invoked has disconnected from its clients
any clue what this means?
-
does anyone know how i can read a header or footer?
i just am not seeing where in the property of the document the header is called out.
-
You might need to "select" something in the document. It seems the header / footer collection is only obtainable through the selection object:
http://msdn.microsoft.com/en-us/library/office/aa172758%28v=office.11%29.aspx
-
im prety sure ive been thru all the properties and the properties of properties of the document and i didnt see anything remotely close to being a header but i will go thru it again now that ive had some sleep and im fresh to go.
-
found it
Command: (vlax-dump-object (vlax-get-property (vlax-get-property
(vlax-get-property(vlax-get-property wa 'ActiveDocument)'sections) 'First)
'Headers))
; HeadersFooters: nil
; Property values:
; Application (RO) = #<VLA-OBJECT _Application 0000000021ef4af8>
; Count (RO) = 3
; Creator (RO) = 1297307460
; Parent (RO) = #<VLA-OBJECT Section 00000000381311e8>
; _NewEnum (RO) = #<IUnknown 0000000033591a20>
T
now how to get the text inside the header?
-
Use vlax-for or vla-item.
;; Gets all the text and appends them to list 'l'
(vlax-for x (setq headers (vlax-get (vlax-get (vlax-get doc 'sections) 'first) 'headers))
(setq l (cons (vlax-get (vlax-get x 'range) 'text) l))
)
;; Gets the item at index 1 <-- Use this to drill down and find properties and methods in the VLIDE
(vla-item headers 1)
-
Use vlax-for or vla-item.
ahhh i was missing something..
i was using
(setq wrds (cons (vlax-get (vlax-get word 'range) 'text) wrds))
but was getting
; error: bad argument type: VLA-OBJECT nil
thanks for the heads up