Jump to content

Microsoft Word Automation Library


big_daddy
 Share

Recommended Posts

  • Replies 115
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Moderators

@ToyleY - Yes, it relies on MS Word's COM Object Model to function. It has been requested before that Word.au3 be compatible with Open Office as well, but that is not going to happen. A quick google search suggested that Open Office does provide COM automation, maybe someone with some time on their hands can start an automation library for it.

Link to comment
Share on other sites

Thank you

I've opted for this:

$printProg = "C:\Program Files\Microsoft Office\OFFICE11\WORDVIEW.EXE "

$printFile = "test.rtf"

$WorkingDir = "C:\Documents and Settings\User\My Documents"

$CommandLine = $printProg & $printFile

run($CommandLine, $WorkingDir, @SW_MAXIMIZE)

Using the free 'MS Word Viewer 2003' From:

http://www.microsoft.com/downloads/details...;displaylang=en

No point in reinventing the wheel and it says on the Microsoft Site: "NOTE: So long as you comply with the other license terms for the Microsoft Office Word 2003 Viewer, you may distribute such viewer without a document created by Microsoft Office."

It prints -

# Rich Text Format (.rtf)

# Text (.txt)

# Web Page formats (.htm, .html, .mht, .mhtml)

# WordPerfect 5.x (.wpd)

# WordPerfect 6.x (.doc, .wpd)

# Works 6.0 (.wps)

# Works 7.0 (.wps)

# XML (.xml)

Unfortunately there is no command line switch (/p, for example) to print documents without using the 'MS Word Viewer 2003' menus, but it's not a big problem.

Link to comment
Share on other sites

  • 2 months later...

There doesn't seem to be a way to attach to Word when there is no Word window. I have script running as a service which launches Word. I can get the pid but haven't figured a way to get a handle or Word object. I'm trying to run a macro when Word opens. I tried using Word's own AutoStart and AutoOpen macros but didn't get it to work. The AutoIt function works perfectly when not running as a service.

Link to comment
Share on other sites

  • 2 weeks later...

hi big_daddy!

#include <Word.au3>

Const $wdStyleHeading1 = -2

$file_name = @ScriptDir & "\index.doc"

$oWordApp = _WordCreate ($file_name, 0, 1)

$oDoc = _WordDocGetCollection ($oWordApp, 0)

xhyxsl_WordContents($oWordApp,$oDoc,2,8)

Func xhyxsl_WordContents($o_WordApp,$o_Doc,$C_Head,$C_Tail)

$x = 0

For $i In $o_Doc.Paragraphs

$x += 1

For $n = $C_Head To $C_Tail

If $x > $C_Tail Then

If $i.Range = $o_Doc.Paragraphs($n).Range Then

$i.Range.Select

$o_WordApp.Selection.Style = $o_Doc.Styles($wdStyleHeading1)

$C_Head += 1

EndIf

EndIf

Next

Next

EndFunc

$i.Range = $o_Doc.Paragraphs($n).Range ;;;==============>>> ???

;;; vba to au3;;;;

;Examples

Sub Contents()

Dim i As Paragraph, n As Byte, a As Byte, b As Byte, x As Long, DelRange As Range

a = 2

b = 8

x = 0

For Each i In Activedocument.Paragraphs

x = x + 1

For n = a To b

If x > b Then

If i.Range = Activedocument.Paragraphs(n).Range Then

i.Range.Select

Selection.Style = Activedocument.Styles(wdStyleHeading1)

a = a + 1

End If

End If

Next

Next

Edited by xhyxsl
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

This is not a question. If you want me to take time to help you, you need to take time to ask a proper question.

BD, this is not his non-question, but a real question of my own... I'm trying to display a .doc file (Public Library User Agreement) and ask the user if he agrees, etc - so it's basically like a "standard" EULA... if he agrees, then I run program X (IE, Firefix, etc), but if he doesn't agree, I inform the librarian so he can call in the SWAT team to deal with the terroristic bastard.

Anyway... It works fine (okay, not fine but more or less acceptably) in a couple of different versions (read file into var & display, yes/no buttons at bottom), but they want it shown in Rich Text, of course...

I'm not seeing anything in your (wonderful) lib that looks like it would work, but I'm probably missing something... am I missing it? If so, how would it be used? Or if not, is there a good way to display beeyoutifull rich text in a non-editable window so I can ask the yes/no in another box?

Thanks - Tex

Nobody needs a job. Not much, anyway. Before you need a job, there's a lot of other stuff you need. More or less in order of how badly you need them: AIR, WATER, FOOD, SHELTER, CLOTHING, COMPANIONSHIP, and ACTIVITY. You've been led to believe you need money to "pay" someone else to provide those for you - all but AIR, so far. How long is it going to be before you have to "pay" for AIR, too?

Link to comment
Share on other sites

@longtex - I'd suggest using a RichEdit control. You can find an example in the help file under "GUICtrlCreateEdit".

It looks promising, but threw an error. Looks like it wanted MSCOMCT2.OCX which was not on my system. I downloaded MSCOMCT2.CAB from ms, put it in \windows\system32 and extracted MSCOMCT2.OCX but I still get two errors - both show an OK box, but time out without user input. The first one is from line 49,

$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

and is styled "invalid class string".

Any idea?

Nobody needs a job. Not much, anyway. Before you need a job, there's a lot of other stuff you need. More or less in order of how badly you need them: AIR, WATER, FOOD, SHELTER, CLOTHING, COMPANIONSHIP, and ACTIVITY. You've been led to believe you need money to "pay" someone else to provide those for you - all but AIR, so far. How long is it going to be before you have to "pay" for AIR, too?

Link to comment
Share on other sites

@longtex:

Did you register the OCX? (regsvr32.exe mscomct2.ocx)

alc

I did, finally. I'm not much of a Windows hand - most of my work is on Linux systems, and the tips I found first, on adding the ocx, didn't say anything about registering... duhhh...

Anyway, after registering, it still throws an error - says it's not licensed for use... I probably need to update - it's an older AU3. I'll do that and report back.

Thanks!

Nobody needs a job. Not much, anyway. Before you need a job, there's a lot of other stuff you need. More or less in order of how badly you need them: AIR, WATER, FOOD, SHELTER, CLOTHING, COMPANIONSHIP, and ACTIVITY. You've been led to believe you need money to "pay" someone else to provide those for you - all but AIR, so far. How long is it going to be before you have to "pay" for AIR, too?

Link to comment
Share on other sites

I did, finally. I'm not much of a Windows hand - most of my work is on Linux systems, and the tips I found first, on adding the ocx, didn't say anything about registering... duhhh...

Anyway, after registering, it still throws an error - says it's not licensed for use... I probably need to update - it's an older AU3. I'll do that and report back.

Thanks!

Apparently, that's not it - I'm updated to the 6/12/2008 version. Same error "not licensed for use"... let's see... yep, same line

$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

Assuming that this gets resolved - it obviously is dependent on the installation of Windows software on the target machine(s), which is something I think we'd all like to avoid: after all, one of the attractions of AU3 is to avoid needing outside libs. What can we do to address this problem?

Nobody needs a job. Not much, anyway. Before you need a job, there's a lot of other stuff you need. More or less in order of how badly you need them: AIR, WATER, FOOD, SHELTER, CLOTHING, COMPANIONSHIP, and ACTIVITY. You've been led to believe you need money to "pay" someone else to provide those for you - all but AIR, so far. How long is it going to be before you have to "pay" for AIR, too?

Link to comment
Share on other sites

Apparently, that's not it - I'm updated to the 6/12/2008 version. Same error "not licensed for use"... let's see... yep, same line

Assuming that this gets resolved - it obviously is dependent on the installation of Windows software on the target machine(s), which is something I think we'd all like to avoid: after all, one of the attractions of AU3 is to avoid needing outside libs. What can we do to address this problem?

Got it - it's a registry problem (apparently). Here's where I found the fix

Now... at least the example doesn't error off (I just copied the example under guictrlcreateedit, as directed). I'll try out the doc file and see if it's going to work...

Still... what does anyone suggest about possibly automating via AU3 the installation and registering of the ocx libs and the registry hack linked above?

Nobody needs a job. Not much, anyway. Before you need a job, there's a lot of other stuff you need. More or less in order of how badly you need them: AIR, WATER, FOOD, SHELTER, CLOTHING, COMPANIONSHIP, and ACTIVITY. You've been led to believe you need money to "pay" someone else to provide those for you - all but AIR, so far. How long is it going to be before you have to "pay" for AIR, too?

Link to comment
Share on other sites

Here's the current resolution to this issue.

As far as I can tell, the richtext controls do NOT display DOC files - however, they DO display RTF files.

I have a program now running, displaying a EULA file in RTF, with Agree/Don't Agree buttons and appropriate action.

Look in Example Scripts, for EULA... this may (probably will) get more attention, but for now, I'm calling it okay.

Thanks for all the help from everyone!

Nobody needs a job. Not much, anyway. Before you need a job, there's a lot of other stuff you need. More or less in order of how badly you need them: AIR, WATER, FOOD, SHELTER, CLOTHING, COMPANIONSHIP, and ACTIVITY. You've been led to believe you need money to "pay" someone else to provide those for you - all but AIR, so far. How long is it going to be before you have to "pay" for AIR, too?

Link to comment
Share on other sites

  • 1 month later...
  • 7 months later...

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...