Sign in to follow this  
Followers 0
GerryIT

Automating WinWord

6 posts in this topic

this code taken from MSDN doesn't seem to work.

any help apprciated...

$appWord = objget("", "Word.Application")

$activeDocument = $appWord.Documents

MsgBox(0, "Select a paragraph in a WinWord apllication", "Select a paragraph to apply the formatting of the first paragraph...")

$oSelection = $appWord.Selection

$oSelection.InsertAfter ("This is a new paragraph.")

$oActive = $appWord.ActiveDocument

; copy the first paragraph formatting

$paraFormat = $oActive.Paragraphs(1).Format.Duplicate

; try to set the copied formatting to the selected paragraph

; the next line does not work, maybe the $paraFormat value is not set properly?

$oSelection.Paragraphs.Format = $paraFormat

Share this post


Link to post
Share on other sites



$appWord = objget("", "Word.Application")
$activeDocument = $appWord.Documents
MsgBox(0, "Select a paragraph in a WinWord apllication", "Select a paragraph to apply the formatting of the first paragraph...")
$oSelection = $appWord.Selection
$oSelection.InsertAfter ("This is a new paragraph.")
$oActive = $appWord.ActiveDocument
; copy the first paragraph formatting
$paraFormat = $oActive.Paragraphs(1).Format.Duplicate
; try to set the copied formatting to the selected paragraph
; the next line does not work, maybe the $paraFormat value is not set properly?
$oSelection.Paragraphs.Format = $paraFormat

makes it nicer to look at

Share this post


Link to post
Share on other sites

did you use object create ... or have an open word program

???

to be able to use objget... you need one or the other

not my area of expertise

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

this code taken from MSDN doesn't seem to work.

any help apprciated...

$appWord = objget("", "Word.Application")

$activeDocument = $appWord.Documents

MsgBox(0, "Select a paragraph in a WinWord apllication", "Select a paragraph to apply the formatting of the first paragraph...")

$oSelection = $appWord.Selection

$oSelection.InsertAfter ("This is a new paragraph.")

$oActive = $appWord.ActiveDocument

; copy the first paragraph formatting

$paraFormat = $oActive.Paragraphs(1).Format.Duplicate

; try to set the copied formatting to the selected paragraph

; the next line does not work, maybe the $paraFormat value is not set properly?

$oSelection.Paragraphs.Format = $paraFormat

There are several things there that seem odd... are you certain it was a working VBS example? Can you post that source? What errors do you getting?

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

the link to msdn is:

http://msdn.microsoft.com/library/default...._HV05210612.asp

with this code:

This example duplicates the paragraph formatting of the first paragraph in the active document and stores the formatting in the variable myDup, and then it changes the left indent for myDup to 1 inch. The example also creates a new document, inserts text into it, and then applies the paragraph formatting stored in myDup to the text.

Activedocument.Range(Start:=0, End:=0).InsertAfter _

"Paragraph Number 1"

Set myDup = Activedocument.Paragraphs(1).Format.Duplicate

myDup.LeftIndent = InchesToPoints(1)

Documents.Add

Selection.InsertAfter "This is a new paragraph."

Selection.Paragraphs.Format = myDup

I tried to modify it to copy the formatting in the same document but without succes.

Share this post


Link to post
Share on other sites

From the MS Office Word 2003 Visual basic reference:

Objects section: ParagraphFormat Object

You can also make a standalone copy of an existing ParagraphFormat object by using the Duplicate property. The following example duplicates the paragraph formatting of the first paragraph in the active document and stores the formatting in myDup. The example changes the left indent of myDup to 1 inch, creates a new document, inserts text into the document, and applies the paragraph formatting of myDup to the text.

Set myDup = Activedocument.Paragraphs(1).Format.Duplicate

myDup.LeftIndent = InchesToPoints(1)

Documents.Add

Selection.InsertAfter "This is a new paragraph."

Selection.Paragraphs.Format = myDup

---

Can this be replicated in AutoIt?

Gerry

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0