Sign in to follow this  
Followers 0
rosanchez

Microsoft Word

16 posts in this topic

Hi, I am a new user of AutoIt. I am trying to paste some .emf files into a word document. The pictures should be placed in determined places inte the document, However, I do not how to do this. I knot that it should be done with the _WordDocAddPicture function, along with the command $o_Range (which specifies the location where the picture will be placed in the text)

Please, can someone help me?

Thank you

Share this post


Link to post
Share on other sites



From the help file...

; *******************************************************
; Example 1 - Create a word window with a new blank document,
;               then add some pictures to the document.
; *******************************************************
;
#include <Word.au3>

$sPath = @WindowsDir & "\"
$search = FileFindFirstFile($sPath & "*.bmp")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No images found")
    Exit
EndIf

$oWordApp = _WordCreate ()
$oDoc = _WordDocGetCollection ($oWordApp, 0)

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $oShape = _WordDocAddPicture ($oDoc, $sPath & $file, 0, 1)
    If Not @error Then $oShape.Range.InsertAfter (@CRLF)
WEnd

; Close the search handle
FileClose($search)

Share this post


Link to post
Share on other sites

Thank you DjDeep00. An additional question. How do you implement the command

$o_Range in order to paste the figure in a desired place into the word document.

From the help file...

; *******************************************************
; Example 1 - Create a word window with a new blank document,
;               then add some pictures to the document.
; *******************************************************
;
#include <Word.au3>

$sPath = @WindowsDir & "\"
$search = FileFindFirstFile($sPath & "*.bmp")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No images found")
    Exit
EndIf

$oWordApp = _WordCreate ()
$oDoc = _WordDocGetCollection ($oWordApp, 0)

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $oShape = _WordDocAddPicture ($oDoc, $sPath & $file, 0, 1)
    If Not @error Then $oShape.Range.InsertAfter (@CRLF)
WEnd

; Close the search handle
FileClose($search)

Share this post


Link to post
Share on other sites

All in the help file....

_WordDocAddPicture ( ByRef $o_object, $s_FilePath [, $b_LinkToFile = 0 [, $b_SaveWithDocument = 0 [, $o_Range = ""]]] )

$o_Range - Optional: The location where the picture will be placed in the text.

"" = (Default) The picture is placed automatically

Any range object

Share this post


Link to post
Share on other sites

Thank you DjDeep00. An additional question. How do you implement the command

$o_Range in order to paste the figure in a desired place into the word document.

See if this example is what you are looking for.

Word - Find Text/Insert Image After

Share this post


Link to post
Share on other sites

Hi Big Daddy, I was trying this script, it does not paste the pictures in the document. Can the pictures be pasted in some desired places.

Thank you

Share this post


Link to post
Share on other sites

Yes they can, and the example above is one way of doing it. If you would like a more precise answer, give a more precise scenario.

Share this post


Link to post
Share on other sites

Thanks Big Daddy, you were right, i did not realized that i had to change the name of the picture.

One more question. Imagine that you have the following word document:

Text

Text

Text

Picture 1

Text

Text

Text

Picture 2

Text

Text

Text

Picture 3

Text

Text

Text

Picture 4

And I want to make a script which pastes the pictures (1-4) in the selected places of the word document. This questions has one purpose. I am a research assistance, I calculate histograms and they change all the time. I use stata so i make a .do file which calculates the histograms and paste them intermediately in the word document. Thanks a lot, and I hope you can help me with this.

Share this post


Link to post
Share on other sites

Two questions:

Is the text already in the document?

Can you provide an example .doc or .docx?

Share this post


Link to post
Share on other sites

Is the text already in the document?

Can you provide an example .doc or .docx?

The text is already in the document, there is sufficient space into the document so the images can be pasted in it. what i want to make is an automatically update of the document. i do not understand the second question.

Thanks again

Share this post


Link to post
Share on other sites

Please Big Daddy, help!!!

Hello Big Daddy, I do not know if you remember my question. I want to paste some pictures in a word document. Your previous script works well, but now I want to paste the pictures in a document which has the following format:

Text

Pict 1.emf

Pict 2.emf

Text

Pict 3.emf

Pict 4.emf

Pict 5.emf

Text

Pict 6.emf

Pict 7.emf

The text was previously created, so every time I have new pictures I want to paste them automatically, because the pictures are updated very often. This is a .doc document.

Thanks a lot

Looking forward to hearing from you

Raul Oscar Sanchez

Universidad Nacional de La Plata

Share this post


Link to post
Share on other sites

I haven't had much time for AutoIt lately, so forgive me for forgetting about this thread. I started working on an example script for this, let me see if I can get it finished sometime today.

Share this post


Link to post
Share on other sites

Thank you Big Daddy. I'll wait your response.

Thanks again.- :)

Share this post


Link to post
Share on other sites

The attached file is the test environment I created for testing. In test.doc the .emf images are in reverse order 7-1, after running the script they will be in order 1-7.

Test.zip

Share this post


Link to post
Share on other sites

:)

Thank very much Big Daddy.

I really appreciatte your help.

Thanks again

Raul Sanchez

Universidad Nacional de La Plata

Share this post


Link to post
Share on other sites

You're welcome!

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