Jump to content
Sign in to follow this  

Ms Word Automation

Recommended Posts


Hi guys,

I am running into a problem with something I thought was pretty simple.

I am working on a script that creates a MS Word document and it needs to change the page orientation to landscape and then insert a image into the page.

i thought that by doing

Send("!f")..etc after "_WordCreate () " to do the landscape would take care of it but it opens the file menu of the script instead of the doc. I thought that the document takes the focus by default (or at least i think that is what the help file says) but it is not the case with this script.

can anyone give me suggestion or a workaround with this issue?

I will really appreciate it

Thanks in advance

Just another special date with a different challenge

Share this post

Link to post
Share on other sites

I dont know what your looking for but this works great for me.

#include <Word.au3>

$sPath = @ScriptDir & "\"
$file = "AW.JPG"

$oWordApp = _WordCreate ('')
$oDoc = _WordDocGetCollection ($oWordApp, 0)
WinActivate('Document1 - ')
WinWaitActive('Document1 - ')
_WordDocAddPicture ($oDoc, $sPath & $file, 0, 1)

While 1

edited sleep time...

Edited by lordicast


Share this post

Link to post
Share on other sites

Hi Santana,

Here is another alterative (sorry not the full prg but should help)...

  $wd = _WordCreate("",0,0,0) ; Start invisible.
  if @error then
    MsgBox(0,"Error","Unable to start word...")

  if $selected_layout = "0" then
    $wd.Activewindow.ActivePane.View.Zoom.Percentage = 85
    $wd.Activewindow.ActivePane.View.Zoom.Percentage = 75

 ; Hide my program now...

  $wd.DisplayAlerts = -1

  $dc = _WordDocGetCollection ($wd, 0)
  $open_doc_count = @extended
 ; MsgBox(0, "Document Count", $open_doc_count)

  $dc.PageSetup.Orientation  = $selected_layout; 0 = Portrait, 1 = Landscape
  $dc.PageSetup.TopMargin   = _Convert_CmToPt(1.0)
  $dc.PageSetup.BottomMargin = _Convert_CmToPt(1.0)
  $dc.PageSetup.LeftMargin   = _Convert_CmToPt(1.0)
  $dc.PageSetup.RightMargin  = _Convert_CmToPt(1.0)

  $bmp = _WordDocAddPicture ($dc, $prtscn_file, 0, 1)
  If Not @error Then $bmp.Range.InsertAfter (@CRLF & @CRLF)

Regards,Andy (no, the other one)

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