MS-Word from PB with COM Interface
Can not seem to get the Excel example to work.
Can someone please provide a detailed list on getting the Excel Example to work.
I keep getting errors, saying that I have a error in the Pb include file, saying the the structure or interface is already declared double.
Help.
Blair
I keep getting errors, saying that I have a error in the Pb include file, saying the the structure or interface is already declared double.
Help.
Blair
Could you tell which Interface is declared double? Do you use the Excel.res file or not? I suggest you disable (delete?) the Excel.res file if you're using it.
Generate a new Interface description with the Interface generator. You can include this with your program. If you get remarks over double Interfaces again, you can rename your Interface in the include file. You have to rename references to this Interface too then!
The (simple) example in this post works as it is, without any "Excel.res" file. I suggest you try that first.
Generate a new Interface description with the Interface generator. You can include this with your program. If you get remarks over double Interfaces again, you can rename your Interface in the include file. You have to rename references to this Interface too then!
The (simple) example in this post works as it is, without any "Excel.res" file. I suggest you try that first.
Managed to do a find in a word document. However, I'm still having problems with the HomeKey and get_Text functions.
(Trying to make a report-engine using MS-Word.)
(Trying to make a report-engine using MS-Word.)
Code: Select all
If oWord\get_Selection(@oSel) = #S_OK
; oSel\HomeKey(#wdStory,#wdMove,None) => does not work
If oSel\get_Find(@oFind.wdFind) = #S_OK
oFind\ClearFormatting()
Tag.VARIANT\vt = #VT_BSTR
Tag\bstrVal = SysAllocString_(Ansi2Uni("\<S\>*\</S\>"))
Order.VARIANT\vt = #VT_BSTR
Order\bstrVal = SysAllocString_(Ansi2Uni("Z"))
;Try finding <S>*</S> in the document
If oFind\ExecuteOld(Tag, vFALSE, vFALSE, vTRUE, vFALSE, vFALSE, vTRUE, vFALSE, vFALSE, Order ,vFALSE, vFalse) = #S_OK
;Now we want to obtain the text between the tags ... => does not work
value.VARIANT\vt = #VT_BSTR
If oSel\get_Text(Tekst) = #S_OK
Debug Uni2Ansi(value\bstrVal)
EndIf
EndIf
EndIf
EndIf
If you look at the description of the HomeKey method
The first two parameters are VARIANTS. You have to pass VARIANTs. The last parameter is an output parameter. The parameter points to the number of positions that the selection has moved. This means that you should code
The same for the get_Text method. The description is
The parameter is an output variable. You should code
I hope this helps, I wasn't able to test this snippet.
Code: Select all
HRESULT HomeKey(
[in, optional] VARIANT* Unit,
[in, optional] VARIANT* Extend,
[out, retval] long* prop);
Code: Select all
v1.VARIANT\vt = #VT_UI4
v1.value = #wdStory
v2.VARIANT\vt = #VT_UI4
v1.value = #wdMove
oSel\HomeKey(v1,v2,@pos.l)
Code: Select all
HRESULT Text([out, retval] BSTR* prop)
Code: Select all
If oSel\get_Text(@Tekst.l) = #S_OK
Debug Uni2Ansi(Tekst)
EndIf
I found that I made some mistakes in the coding. With me this works now:
Code: Select all
v1.VARIANT\vt = #VT_UI4
v1\value = #wdStory
v2.VARIANT\vt = #VT_UI4
v2\value = #wdMove
oSel\HomeKey(v1,v2,@pos.l)
Debug pos
Following code does work :
but
does not work ...
I'm using Word 2002,WinXP and PB3.90
BTW Where can I find the description like HRESULT HomeKey( [in, optional] ....
I only found this http://msdn.microsoft.com/library/defau ... omekey.asp
Many thanks.
Code: Select all
v1.VARIANT\vt = #VT_I2
v1\value = #wdStory
oSel\HomeKey(v1,None,@pos.l)
Code: Select all
v1.VARIANT\vt = #VT_UI4
v1\value = #wdStory
oSel\HomeKey(v1,None,@pos.l)
I'm using Word 2002,WinXP and PB3.90
BTW Where can I find the description like HRESULT HomeKey( [in, optional] ....
I only found this http://msdn.microsoft.com/library/defau ... omekey.asp
Many thanks.
I have found that it is sometimes try and error to get the right VARIANT type. For me the #VT_UI4 worked.
To get the parameter description I built the Interface Generator. This shows interface descriptions, structures and enumerations. You can download it from http://home.planet.nl/~aXend/purebasic/ ... erator.zip.
If you type word.application and click on create interface then you can find the interface description of Selection and if you click on the method HomeKey then you find the description of the parameters.
You can find more info at the forum. See viewtopic.php?t=11031
To get the parameter description I built the Interface Generator. This shows interface descriptions, structures and enumerations. You can download it from http://home.planet.nl/~aXend/purebasic/ ... erator.zip.
If you type word.application and click on create interface then you can find the interface description of Selection and if you click on the method HomeKey then you find the description of the parameters.
You can find more info at the forum. See viewtopic.php?t=11031
Re: MS-Word from PB with COM Interface
Hi,
Does anybody still have a copy of Interface Generator v1.0 and the Word and Excel .res files stashed away somewhere. I know this is a very old post, I've tried searching but only come back to the same dead links.
Does anybody still have a copy of Interface Generator v1.0 and the Word and Excel .res files stashed away somewhere. I know this is a very old post, I've tried searching but only come back to the same dead links.
Re: MS-Word from PB with COM Interface
I have a copy of interface generator. If you pm me an email address then I am happy to email it your way.
I may look like a mule, but I'm not a complete ass.
Re: MS-Word from PB with COM Interface
Sorry I should have posted back to say I've now got a copy curtesy of mk-soft.
Thanks anyway.
Thanks anyway.
Re: MS-Word from PB with COM Interface
Hello,
same for me: Is there anyone out there who could email me the zip file(s) since they are no longer available using the original links? They haven't been archived by archive.org either because they weren't publicy linked from http://home.planet.nl/~aXend at the time this homepage was alive.
Thank you very much in advance, Jens-Arne
same for me: Is there anyone out there who could email me the zip file(s) since they are no longer available using the original links? They haven't been archived by archive.org either because they weren't publicy linked from http://home.planet.nl/~aXend at the time this homepage was alive.
Thank you very much in advance, Jens-Arne
Re: MS-Word from PB with COM Interface
Sometime ago i converted the typelib with a tool a wrote, here is the pb include (MSWORD.pbi):
https://github.com/omegakode/PBMSWord
i just tested this basic code and it works:
https://github.com/omegakode/PBMSWord
i just tested this basic code and it works:
Code: Select all
EnableExplicit
XIncludeFile "MSWORD.pbi"
Define._Application wdApp
OleInitialize_(0)
If CoCreateInstance_(?CLSID_Application, 0, #CLSCTX_LOCAL_SERVER, ?IID__Application, @wdApp) <> #S_OK
MessageRequester("Warning:","Couldn't init oWord",0)
End
EndIf
wdApp\Activate()
wdApp\put_WindowState(#wdWindowStateNormal)
wdApp\put_Width(400)
wdApp\put_Height(300)
wdApp\put_Left(10)
wdApp\put_Top(10)
wdApp\put_Caption("Word from PureBasic")
wdApp\put_Visible(#True)
wdApp\Release()
OleUninitialize_()
Re: MS-Word from PB with COM Interface
Thank you very much! The example program opens WinWord without a new document for me (just the main program with the new caption).
Now the big question is: How do I use this interface? A help file of some kind would be great. Probably it's a bit too huge an effort to cover all the functions, but a basic concept would help enormously.
Best regards, Jens-Arne
Now the big question is: How do I use this interface? A help file of some kind would be great. Probably it's a bit too huge an effort to cover all the functions, but a basic concept would help enormously.
Best regards, Jens-Arne