Author Topic: MSWord, Portrait or Landscape  (Read 2550 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Bull Frog
  • Posts: 242
MSWord, Portrait or Landscape
« on: August 30, 2015, 07:25:12 PM »
How to put a MSWord document in portrait or landscape?
OK.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: MSWord, Portrait or Landscape
« Reply #1 on: August 30, 2015, 08:06:10 PM »
Check out this link.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

FELIX

  • Bull Frog
  • Posts: 242
Re: MSWord, Portrait or Landscape
« Reply #2 on: August 30, 2015, 08:14:54 PM »
You're having fun with me. The forum is Autolisp.
OK.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: MSWord, Portrait or Landscape
« Reply #3 on: August 31, 2015, 07:36:08 AM »
Use the orientation property of the pagesetup object.

Here is a quick example:
Code - Auto/Visual Lisp: [Select]
  1. ;; Set Word Document Orientation  -  Lee Mac
  2.  
  3. (defun c:test ( / app:flg doc doc:flg err msw:app msw:dcs msw:doc msw:pgs ori )
  4.     (if (setq doc (getfiled "" "" "docx;doc" 16))
  5.         (progn
  6.             (initget "Portrait Landscape")
  7.             (setq ori (if (= "Portrait" (getkword "\nSet document to [Portrait/Landscape] <Landscape>: ")) 0 1))
  8.            
  9.             (if (or (and (setq msw:app (vlax-get-object "word.application"))
  10.                          (setq app:flg t)
  11.                     )
  12.                     (setq msw:app (vlax-create-object "word.application"))
  13.                 )
  14.                 (progn
  15.                     (setq err
  16.                         (vl-catch-all-apply
  17.                            '(lambda nil
  18.                                 (vlax-for obj (setq msw:dcs (vlax-get-property  msw:app 'documents))
  19.                                     (if (= (strcase doc) (strcase (vlax-get-property obj 'fullname)))
  20.                                         (setq msw:doc obj
  21.                                               doc:flg t
  22.                                         )
  23.                                     )
  24.                                 )
  25.                                 (if (null msw:doc)
  26.                                     (setq msw:doc (vlax-invoke-method msw:dcs 'open doc))
  27.                                 )
  28.                                 (setq msw:pgs (vlax-get-property msw:doc 'pagesetup))
  29.                                 (vlax-put-property msw:pgs 'orientation ori)
  30.                                 (if (not doc:flg)
  31.                                     (progn
  32.                                         (vlax-invoke-method msw:doc 'save)
  33.                                         (vlax-invoke-method msw:doc 'close)
  34.                                         (if (not app:flg)
  35.                                             (vlax-invoke-method msw:app 'quit)
  36.                                         )
  37.                                     )
  38.                                 )
  39.                             )
  40.                         )
  41.                     )
  42.                     (foreach obj (list msw:pgs msw:doc msw:dcs msw:app)
  43.                         (if (= 'vla-object (type obj))
  44.                             (vlax-release-object obj)
  45.                         )
  46.                     )
  47.                     (if (vl-catch-all-error-p err)
  48.                         (princ (strcat "\nError setting page orientation: " (vl-catch-all-error-message err)))
  49.                     )
  50.                 )
  51.                 (princ "\nUnable to interface with Word application.")
  52.             )
  53.         )
  54.         (princ "\n*Cancel*")
  55.     )
  56.     (princ)
  57. )

FELIX

  • Bull Frog
  • Posts: 242
Re: MSWord, Portrait or Landscape
« Reply #4 on: August 31, 2015, 08:31:10 AM »
Thank you so much.
Enough only the following line:

Code: [Select]
(vlax-put-property msw:pgs 'orientation ori)
And for the four mages, as is the code line?
OK.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: MSWord, Portrait or Landscape
« Reply #5 on: August 31, 2015, 08:49:27 AM »
You're having fun with me. The forum is Autolisp.
Oops!  Sorry about that.   :embarrassed:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: MSWord, Portrait or Landscape
« Reply #6 on: August 31, 2015, 08:59:26 AM »
Thank you so much.
Enough only the following line:

Code: [Select]
(vlax-put-property msw:pgs 'orientation ori)
And for the four mages, as is the code line?

I'm guessing you mean 'margins'?

If so, use the appropriate properties of the pagesetup object:

topmargin
bottommargin
leftmargin
rightmargin

I'm sure you could have found those yourself, given the links I have already provided...  :wink: