Jump to content

Microsoft Word


 Share

Recommended Posts

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

Link to comment
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)
Link to comment
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)
Link to comment
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

Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...