From: MikkelFJ Date: 2002-08-06T03:59:27+09:00 Subject: Re: win32ole and excel Masaki Suketa wrote in news:200208051208.VAA05514@ums509.nifty.ne.jp: > FYI, The "method_missing" is because of the trick of Win32OLE. Right - I see that now. >> [id(0x00000022), helpstring("method Save")] >> HRESULT Save([in, optional] VARIANT destination); > Hmm, what happen when you omit optional argument? > > mdm.Save I get a "Missing FileName" exception, but it is what you would expect. If the document had been opened first, it would save with that filename. Or, as is the case in the following script where I actually manage to save the document, the second call to Save do not need a name - and it does work. require 'win32ole' include WIN32OLE::VARIANT mralias = WIN32OLE.new('mrAliasMap.Mapper') puts mralias.CreateAlias("this is a long name").Name mdm = WIN32OLE.new('MDM.Document.2') mdm._invoke(0x00000022, ['testfile_invoke.mdd'], [VT_BSTR]) mdm.Save puts 'done' > > Unfortunately, WIN32OLE can not handle VARIANT type argument > correctly. Will that be fixed? I haven't tried the following, but a prerelease of OCam'Ole has just been released a few days ago. There might be some useful VARIANT code in the C interface. http://tech.motion-twin.com/ > For example, AppendChunk of SQLServer (ADODB.Connection) accept one > VARIANT type argument. But, to use AppendChunk from Win32OLE, you > must use _invoke as following. > > obj._invoke(0x00000453, [data.unpack('C*')], [VT_ARRAY|VT_UI1]) > > So, How about > > mdm._invoke(0x00000022, ['testfile.mdd'], [VT_VARIANT]) after including WIN32OLE::VARIANT it could run, but generated type error. > or specify correct type directly. > > data = 'testfile.mdd' > mdm._invoke(0x0000022, [convert_correct_type(data)], [???]) As you can see in the script, VT_BSTR did the job. So this is great in the sense that it now works, but it isn't very practical as a lot of COM components do use the VARIANT type. Regards Mikkel