Jump to content

Recommended Posts

Posted

To optimize my program access to MSWORD without accessing table OLB need to modify a line in the code below:

 

;(IF (NOT TBLMSWORD)
;    (PROGN
;    (SETQ TBLMSWORD (STRCAT #DRV "MSWORD.OLB"))
;    (vlax-import-type-library 
;     :tlb-filename TBLMSWORD 
;     :methods-prefix "MSWORDm-" 
;     :properties-prefix "MSWORDp-" 
;     :constants-prefix "MSWORDc-" 
;    ) 
;    )

;;;
(setq MSWORDAPP (vlax-get-or-create-object "Word.Application")) 
(vla-put-visible MSWORDAPP :vlax-true) 
(setq docs (vla-get-documents MSWORDAPP)) 
(SETQ doc  (vlax-invoke-method docs 'Add))
(setq paragraphs (vlax-get-property doc 'Paragraphs)) 
(setq pg (vlax-get-property paragraphs 'last)) 
(setq range (vlax-get-property pg 'range)) 
(vlax-put-property (vlax-get-property range 'font) 'name  "COURIER NEW") 
(vlax-put-property (vlax-get-property range 'font) 'size  15)
;
(setq WDRANGE (vlax-get-property (vlax-get-property (vlax-get-property MSWORDAPP 'ActiveDocument) 'WORDS) 'last)) 
;(mswp-put-alignment (mswp-get-ParagraphFormat range) mswc-wdAlignParagraphCenter)
[b](vlax-put-property (vlax-get-property range 'Alignment) 'ParagraphFormat  'wdAlignParagraphCenter) ;<< Error in this line[/b]
(vlax-invoke-method range 'InsertAfter "TEXTO NEGRITO, ")
;;;

 

OK...

Posted (edited)

Try instead:

(vlax-put-property (vlax-get-property range 'Alignment) 'ParagraphFormat 1)

or:

 
(vlax-put-property
(vlax-get-property range 'Alignment)
'ParagraphFormat (vlax-make-variant 1 3));<--variant of long

Possible alignment constants are 0,1,2

 

To get numeric values of any constants just type in the Word VBA editor

in the immediate window Type: ?wdAlignParagraphCenter and press Enter

Same for other stuffs, just don't you forget to type question sign at front of constant

 

But I'm not sure abot that the word is have an alignment property

Perhaps, better use paragraph range instead, not tested

 
(setq WDRANGE (vlax-get-property (vlax-get-property (vlax-get-property MSWORDAPP 'ActiveDocument) [b]'Paragraphs[/b]) 'last))

Edited by fixo
spell check
Posted

Or use something like this function, it's written in editor so test it before

 

 
;change paragraph alignment 
(defun ApplyAlignment (para typ /  parform parrange) ;usual types are: 0 1 2 
(setq parrange (vlax-get-property para 'Range))
 (setq parform (vlax-get-property parrange 'ParagraphFormat))
 (vlax-put-property parform 'Alignment (vlax-make-variant typ 3))
 )

Posted
Again thank you so much.

 

OK.

You're welcome

Cheers :)

 

~'J'~

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...