Jump to content
Sign in to follow this  
big_daddy

Microsoft Word Automation Library

Recommended Posts

@randallc - I've been doing some testing, by chance are you initially opening the document via script?

There seems to be a bug with _WordAttach() not finding documents opened via script; however it works fine when the document is opened manually. :)

Share this post


Link to post
Share on other sites

Hi,

It seems to be either way for me! - I was originally doing it manually; now I see I have the problem either way.

Seems that "isobj"=1 $oWindows does not have a collection in it, despite existing???...!

Best, Randall

[EDIT; PS later; it is working?!.. I give up]

Edited by randallc

Share this post


Link to post
Share on other sites

Is it possible to have an Openoffice udf inside Word.au3...

where they should have same funcs and you can use an global var in the apps where you can decide when to change from one to another:

example:

include word.au3

$Wordactiveprocessor="OPEN"

.... CODE valid FOR OPENOFFICE

$WordActiveProcessor="Word"

.... Code valid for Word

$WordActiveProcessor="Excel"

..... Code valid for Exce

Same functions same things...

It is a great UDF,

Thanks for supporting the free software :) OO

Edited by BasicOs

Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http

Share this post


Link to post
Share on other sites

New update available! See update history in first post for changes.

Enjoy,

Bob

@BasicOs - I probably won't add this to Word.au3, but I could possibly create an add-on for Open Office.

Share this post


Link to post
Share on other sites

This is great... keep up the good work!

Now we just need an excel and outlook udf :)

Share this post


Link to post
Share on other sites

This is great... keep up the good work!

Now we just need an excel and outlook udf :)

For an Excel udf see the signature of randallc, 3 posts up.... :P

Share this post


Link to post
Share on other sites

Looks really nice Bob!!!

just a small note.. may help reduce the amount of lines required in this larger type of file

i see alot of this... or similar

If @error Then
        SetError(@error, @extended)
        Return False
    EndIfoÝ÷ Û^ØZµÊ.ÖÞ­çnqçm¢;¬·Yb殶­s`¤bW'&÷"FVâ&WGW&â6WDW'&÷"W'&÷"ÂWFVæFVBÂfÇ6R²÷"

... AFAIK

Valuater

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Since disk space is charged in bytes rather than lines, i would choose the first structure for readability and flexibility...

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

For an Excel udf see the signature of randallc, 3 posts up.... :)

Heh, hmmm, well... aren't i watchful :P very nice randallc. Once "we" (and by that i mean all of you guys that aren't complete n00bs. like me) get the full office suite done i suppose it'll make it to the stable release. That'd be sweet.

Share this post


Link to post
Share on other sites

I was trying to use your _WordDocAddPicture function and I cannot seam to get it to work with .png files. I receive this console error "--> Word.au3 Error from function _WordDocAddPicture, $_WordStatus_InvalidObjectType" when I run the following code.

#include <Word.au3>
$oWordApp = _WordCreate ("C:\Documents and Settings\All Users\Desktop\WordOutput.doc", 0, 0)
$sPath = "C:\Program Files\Temp\"
$file = "MWSnap.png"
$oShape = _WordDocAddPicture ($oWordApp, $sPath & $file, 0, 1)
_WordQuit ($oWordApp)

I had been using my own code to do this so I am not sure why it will not work using your function. They appear to be similiar except I am using ".Selection".

Code that will insert .png files.

#include <Word.au3>
$gWord = ObjCreate("Word.Application")
$gWord.visible = False
$gWord.Documents.Add
$sPath = "C:\Program Files\Temp\"
$file = "MWSnap.png"
$gWord.Selection.InlineShapes.AddPicture( $sPath & $file, False, True)
$gWord.ChangeFileOpenDirectory (@DesktopDir)
$gWord.Activedocument.SaveAs ("WordOutput.doc")
$gWord.Application.Quit

Kohr

Edited by Kohr

Share this post


Link to post
Share on other sites

@Kohr - The first parameter for _WordDocAddPicture() needs to be a document object, whereas your trying to pass an application object. Please take a look at the help file, there you will find an example of how to correctly use the function.

Thanks,

Bob

Share this post


Link to post
Share on other sites

Thanks. I got the function to work. Any idea why the 1st method works and the 2nd does not?

Works.

#include <Word.au3>
$oWordApp = _WordCreate ("", 0, 0)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
$sPath = "C:\Program Files\Temp\"
$file = "MWSnap.png"
$oShape = _WordDocAddPicture ($oDoc, $sPath & $file, 0, 1)
_WordDocSaveAs ($oDoc, @DesktopDir & "\WordOutput.doc")
_WordQuit ($oWordApp)

Does not work.

#include <Word.au3>
$oWordApp = _WordCreate (@DesktopDir & "\WordOutput.doc", 0, 0)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
$sPath = "C:\Program Files\Temp\"
$file = "MWSnap.png"
$oShape = _WordDocAddPicture ($oDoc, $sPath & $file, 0, 1)
_WordDocSave ($oDoc)
_WordQuit ($oWordApp)

I mainly want to understand these more so I can decide if I want to use them. I basically use word to write a combination of txt and picture inserts on 100+ pages in a single word document. Everything I did is not function based but I would like to move to yours if possible.

Kohr

Edited by Kohr

Share this post


Link to post
Share on other sites

Is it possible to run spellchecking on a word document?

What I am doing is the following:

I have a program which helps translators to correct their translated text against the original text. This is a GUI with two synchronised multiline Edit Ctrl with very special functions to speed up comparison of original and translated text. (The translated text normally is not made in MS Word)

I would like to add the functionality of spellchecking the translated text using Word spellchecker. Word is installed on everyone's computer (translators) with the local spellchecking so it should not be a problem to use it.

Based on the cool Word UDF I can insert my sentence to a word this should be no problem. But can I run the spellchecking somehow (preferably in hidden mode) and show results through my AutoIt GUI?

According to http://msdn2.microsoft.com/en-us/library/ms178794.aspx (Which is: How to: Check Spelling in Documents), there is a way of doing it, but I am not expert on this.

Thanks for your help

Share this post


Link to post
Share on other sites

@Ármányos Kő

This should you get started.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x / NT
; Author:         Jos van der Zande <jvdzande@yahoo.com>
;
; Script Funktion:
;   Spell checks the Selected text with the Word spellchecker and 
; Paste it back if updated.;
; ----------------------------------------------------------------------------
; set to the MS language number you want 
Global $Language = "1033"  ; English
$S = ClipGet()       ; save clip content
ClipPut("")          ; empty clipboard
Send("^{INSERT}")    ; get selection to clipboard
$ORG_SELECTION=ClipGet() ; Get current selection
If $ORG_SELECTION = "" Then Function:
   TrayTip('SpellCheck','No text Selected !!',3)
   Sleep(3000)
Else
   ; get active window title and minimise
   $WINTITLE = WinGetTitle("")
   ; hide the window to ensure its not changed during spellcheck
   WinSetState($WINTITLE,'',@SW_MINIMIZE)
   ; find number of leading spaces
   For $SS = 0 To StringLen($ORG_SELECTION) - 1
      If StringMid($ORG_SELECTION,$SS+1,1) <> " " Then ExitLoop
   Next 
   ; find number of trailing spaces
   For $ST = 0 To StringLen($ORG_SELECTION) - 1
      If StringMid($ORG_SELECTION,StringLen($ORG_SELECTION) - $ST,1) <> " " Then ExitLoop
   Next 
   ; set traytip and Create/Run spellcheck vbs 
   TrayTip('Running SpellCheck for',StringLeft($ORG_SELECTION,30) & "...",5)
   CreateVBScript()
   $RC=RunWait(@ComSpec & ' /c Wscript.exe "' & @ScriptDir & '\TextSpellCheck.vbs" 1033',"",@SW_HIDE)
   ; restore window
   WinSetState($WINTITLE,'',@SW_RESTORE)
   WinActivate($WINTITLE,'')
   ; strip spaces and add original number of leading/trailing spaves
   $SELECTION=StringStripWS(ClipGet(),3) ; Get current selection
   If $SELECTION<>StringStripWS($ORG_SELECTION,3) Then
      For $X = 1 To $SS
         $SELECTION = " " & $SELECTION
      Next
      For $X = 1 To $ST
         $SELECTION = $SELECTION & " "
      Next
      ; update clipboard
      ClipPut($SELECTION)
      ; paste updated text
      Send("+{INSERT}")
      TrayTip('SpellCheck','Text updated.',4)
   Else
      TrayTip('SpellCheck','Text ok, no updates.',4)
   EndIf
EndIf
; restore orignal clipboard contents
ClipPut($S)
sleep(4000)
FileDelete(@ScriptDir & '\TextSpellCheck.vbs')

Func CreateVBScript()
   FileDelete(@ScriptDir & '\TextSpellCheck.vbs')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','On error resume next')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Set Word = CreateObject("word.Application")')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Word.WindowState = 2')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Word.Visible = False')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Set Doc = Word.Documents.Add( , , 1, True)')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Word.Selection.Paste')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','If err = 0 then')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  Word.Selection.LanguageID = ' & $Language)
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  ''Doc.CheckSpelling  '' Spellcheck function')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  Doc.CheckGrammar    '' Spelling And Grammer check function')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  Word.Selection.WholeStory')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  Word.Selection.Copy')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','End If')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Doc.Close False')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Word.Application.Quit True')
EndFunc   ;==>CreateVBScript

Enjoy !!

ptrex


Share this post


Link to post
Share on other sites

Ptrex!

This seems pretty promising!

Is it a right feeling that in

$RC=RunWait(@ComSpec & ' /c Wscript.exe "' & @ScriptDir & '\TextSpellCheck.vbs" 1033',"",@SW_HIDE)

the 1033 should also be changed to local language code ($language)?

Thank you very much for the quick help!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...