Page 3 of 5
Posted: Tue Jun 01, 2004 10:17 am
by Fred
Nice work guys !
Can not seem to get the Excel example to work.
Posted: Sat Jun 05, 2004 5:19 am
by BlairH
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
Posted: Sat Jun 05, 2004 10:01 am
by aXend
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.
Posted: Fri Jun 25, 2004 8:55 am
by LuckyLuke
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.)
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
Posted: Fri Jun 25, 2004 12:31 pm
by aXend
If you look at the description of the HomeKey method
Code: Select all
HRESULT HomeKey(
[in, optional] VARIANT* Unit,
[in, optional] VARIANT* Extend,
[out, retval] long* prop);
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
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)
The same for the get_Text method. The description is
Code: Select all
HRESULT Text([out, retval] BSTR* prop)
The parameter is an output variable. You should code
Code: Select all
If oSel\get_Text(@Tekst.l) = #S_OK
Debug Uni2Ansi(Tekst)
EndIf
I hope this helps, I wasn't able to test this snippet.
Posted: Fri Jun 25, 2004 3:17 pm
by LuckyLuke
Thanks aXend !
The get_Text is working fine.
But the HomeKey still fails.

Posted: Fri Jun 25, 2004 3:41 pm
by aXend
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
Posted: Mon Jun 28, 2004 9:16 am
by LuckyLuke
Following code does work :
Code: Select all
v1.VARIANT\vt = #VT_I2
v1\value = #wdStory
oSel\HomeKey(v1,None,@pos.l)
but
Code: Select all
v1.VARIANT\vt = #VT_UI4
v1\value = #wdStory
oSel\HomeKey(v1,None,@pos.l)
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.
Posted: Mon Jun 28, 2004 9:38 am
by aXend
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
Re: MS-Word from PB with COM Interface
Posted: Sat Jul 08, 2017 10:41 pm
by Ajm
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.
Re: MS-Word from PB with COM Interface
Posted: Wed Jul 12, 2017 8:54 am
by srod
I have a copy of interface generator. If you pm me an email address then I am happy to email it your way.
Re: MS-Word from PB with COM Interface
Posted: Wed Jul 12, 2017 9:40 am
by Ajm
Sorry I should have posted back to say I've now got a copy curtesy of mk-soft.
Thanks anyway.
Re: MS-Word from PB with COM Interface
Posted: Sun Feb 04, 2024 11:14 am
by Jens-Arne
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
Re: MS-Word from PB with COM Interface
Posted: Mon Feb 19, 2024 2:52 pm
by Justin
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:
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
Posted: Mon Feb 19, 2024 5:26 pm
by Jens-Arne
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