[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Need help with win320le word interface

andyh47

7/5/2005 8:52:00 PM

I'm writing a report generator which uses word for formatting. In
expermeniting with win32ole this code works:

require 'win32ole'


w = WIN32OLE.new('Word.Application')
w.visible=TRUE
w.Documents.Add
doc=w.ActiveDocument
doc.Content.Font.Name = 'Arial'
doc.Content.Font.Size = 10
doc.Content.Font.Bold = TRUE
selection = w.selection
selection.typetext "Hello World"


However when I add this line to get the cursor positon:

curpos = selection.Information['wdHorizontalPositionRelativeToPage']


I get this error. does anyone know why? thanks for the help.

C:/PROGRA~1/Ruby/work/bell05/efo~7.rb:14:in `method_missing': Information
(WIN32OLERuntimeError)
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x8002000e
Invalid number of parameters. from
C:/PROGRA~1/Ruby/work/bell05/efo~7.rb:14

The offending command works when executed in VBWord.


3 Answers

Corey Lawson

7/5/2005 9:27:00 PM

0

Use the Object Inspector in VBA to see what is the numeric value of
wdHorizontalPositionRelativeToPage, and pass that in, instead of the
tag.

Win32OLE doesn't know about those constants or enumerations.

It's the same hoop to jump through with VBScript, too...


On 7/5/05, andyh47 <andyh@synplicity.com> wrote:
> I'm writing a report generator which uses word for formatting. In
> expermeniting with win32ole this code works:
>
> require 'win32ole'
>
>
> w = WIN32OLE.new('Word.Application')
> w.visible=TRUE
> w.Documents.Add
> doc=w.ActiveDocument
> doc.Content.Font.Name = 'Arial'
> doc.Content.Font.Size = 10
> doc.Content.Font.Bold = TRUE
> selection = w.selection
> selection.typetext "Hello World"
>
>
> However when I add this line to get the cursor positon:
>
> curpos = selection.Information['wdHorizontalPositionRelativeToPage']
>
>
> I get this error. does anyone know why? thanks for the help.
>
> C:/PROGRA~1/Ruby/work/bell05/efo~7.rb:14:in `method_missing': Information
> (WIN32OLERuntimeError)
> OLE error code:0 in <Unknown>
> <No Description>
> HRESULT error code:0x8002000e
> Invalid number of parameters. from
> C:/PROGRA~1/Ruby/work/bell05/efo~7.rb:14
>
> The offending command works when executed in VBWord.
>
>
>
>


Dave Burt

7/5/2005 9:33:00 PM

0

"andyh47" <andyh@synplicity.com> asked:
>
> require 'win32ole'
>
> ...
>
> curpos = selection.Information['wdHorizontalPositionRelativeToPage']

The above is not a correct translation of the VB code you are using:
curpos = Selection.Information(wdHorizontalPositionRelativeToPage)

wdHorizontalPositionRelativeToPage is a constant integer whose value is 5.
(Try printing it or displaying it in a msgbox from Word/VBA.

Furthermore, Information has a required argument, and you need to pass that
as a Ruby argument rather than using the [] operator as you're doing here.

Try this:
WdHorizontalPositionRelativeToPage = 5
curpos = selection.Information(WdHorizontalPositionRelativeToPage)
or this:
module Word; end # you can use whatever name you like instead of Word
WIN32OLE.const_load(w, Word)
curpos = selection.Information(WdHorizontalPositionRelativeToPage)

Cheers,
Dave


andyh47

7/6/2005 6:44:00 PM

0

Thanks very much for your post and the one from Corey. The advice worked
like a charm. Thanks very much for your help.


"Dave Burt" <dave@burt.id.au> wrote in message
news:V%Cye.15665$oJ.2679@news-server.bigpond.net.au...
> "andyh47" <andyh@synplicity.com> asked:
>>
>> require 'win32ole'
>>
>> ...
>>
>> curpos = selection.Information['wdHorizontalPositionRelativeToPage']
>
> The above is not a correct translation of the VB code you are using:
> curpos = Selection.Information(wdHorizontalPositionRelativeToPage)
>
> wdHorizontalPositionRelativeToPage is a constant integer whose value is 5.
> (Try printing it or displaying it in a msgbox from Word/VBA.
>
> Furthermore, Information has a required argument, and you need to pass
> that as a Ruby argument rather than using the [] operator as you're doing
> here.
>
> Try this:
> WdHorizontalPositionRelativeToPage = 5
> curpos = selection.Information(WdHorizontalPositionRelativeToPage)
> or this:
> module Word; end # you can use whatever name you like instead of Word
> WIN32OLE.const_load(w, Word)
> curpos = selection.Information(WdHorizontalPositionRelativeToPage)
>
> Cheers,
> Dave
>