Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #6560 > unrolled thread

get running instance of word?

Started byJürgen Knauf <trotterklaus@googlemail.com>
First post2014-01-26 06:57 -0800
Last post2014-02-03 03:42 -0800
Articles 12 — 5 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  get running instance of word? Jürgen Knauf <trotterklaus@googlemail.com> - 2014-01-26 06:57 -0800
    Re: get running instance of word? Mathias <mathias.hakansson@consultec.se> - 2014-01-27 01:18 -0800
      Re: get running instance of word? Jürgen Knauf <trotterklaus@googlemail.com> - 2014-01-27 08:19 -0800
        Re: get running instance of word? dlzc <dlzc1@cox.net> - 2014-01-27 10:52 -0800
          Re: get running instance of word? Jürgen Knauf <trotterklaus@googlemail.com> - 2014-01-27 12:57 -0800
            Re: get running instance of word? Mathias <mathias.hakansson@consultec.se> - 2014-01-27 22:20 -0800
              Re: get running instance of word? Mathias <mathias.hakansson@consultec.se> - 2014-01-27 22:36 -0800
                Re: get running instance of word? Malcolm G <malcolm-news2012delete@delete.jobstream.com> - 2014-01-28 10:10 +0000
                  Re: get running instance of word? Mathias <mathias.hakansson@consultec.se> - 2014-01-29 01:22 -0800
    Re: get running instance of word? Jürgen Knauf <trotterklaus@googlemail.com> - 2014-01-30 22:40 -0800
      Re: get running instance of word? MikeScholl@btinternet.com - 2014-02-02 04:38 -0800
        Re: get running instance of word? Jürgen Knauf <trotterklaus@googlemail.com> - 2014-02-03 03:42 -0800

#6560 — get running instance of word?

FromJürgen Knauf <trotterklaus@googlemail.com>
Date2014-01-26 06:57 -0800
Subjectget running instance of word?
Message-ID<b2f1c736-5fbd-405e-8d2b-9910692dfa64@googlegroups.com>
How do i geht the correct instance of a running Word document?

Exspecially when the document is opened after my vo app.

[toc] | [next] | [standalone]


#6561

FromMathias <mathias.hakansson@consultec.se>
Date2014-01-27 01:18 -0800
Message-ID<5a57f576-15e1-483f-8b3f-ee197e7694a9@googlegroups.com>
In reply to#6560
In what context? What are you trying to do? Are you starting the document from your application? Word automation?

I Have c++ code for opening an excel document in an internet Explorer Control, grabbing a handle to the excel application and doing running excel automation. The important part (grabbing the handle) may be hard to translate to VO unless you're a guru.

BOOL CMyDlg::GetExcelDispatch()
{
        CLSID clsid;
        if (CLSIDFromProgID(OLESTR("Excel.Application"), &clsid) != NOERROR)
        {
                AfxMessageBox("Could not find excel clsid!",MB_OK | MB_ICONSTOP);
                return false;
        }

        LPUNKNOWN lpUnk;
        if (GetActiveObject(clsid, NULL, &lpUnk) == NOERROR)
        {
                LPDISPATCH lpDispatch;
                HRESULT hr = lpUnk->QueryInterface(IID_IDispatch,
(LPVOID*)&lpDispatch);
                lpUnk->Release();
                if (hr == NOERROR)
                {
                        m_ExcelApp.AttachDispatch(lpDispatch); // Remember IDispatch.
                        return true;
                }
        }

        return false;
}

/Mathias

Den söndagen den 26:e januari 2014 kl. 15:57:31 UTC+1 skrev Jürgen Knauf:
> How do i geht the correct instance of a running Word document?
> 
> 
> 
> Exspecially when the document is opened after my vo app.

[toc] | [prev] | [next] | [standalone]


#6563

FromJürgen Knauf <trotterklaus@googlemail.com>
Date2014-01-27 08:19 -0800
Message-ID<403dd4ab-f697-4788-b90d-c320545f8751@googlegroups.com>
In reply to#6561
Am Montag, 27. Januar 2014 10:18:57 UTC+1 schrieb Mathias:
> In what context? What are you trying to do? Are you starting the document from your application? Word automation?
> 
> 
> 
> I Have c++ code for opening an excel document in an internet Explorer Control, grabbing a handle to the excel application and doing running excel automation. The important part (grabbing the handle) may be hard to translate to VO unless you're a guru.
> 
> 
> 
> BOOL CMyDlg::GetExcelDispatch()
> 
> {
> 
>         CLSID clsid;
> 
>         if (CLSIDFromProgID(OLESTR("Excel.Application"), &clsid) != NOERROR)
> 
>         {
> 
>                 AfxMessageBox("Could not find excel clsid!",MB_OK | MB_ICONSTOP);
> 
>                 return false;
> 
>         }
> 
> 
> 
>         LPUNKNOWN lpUnk;
> 
>         if (GetActiveObject(clsid, NULL, &lpUnk) == NOERROR)
> 
>         {
> 
>                 LPDISPATCH lpDispatch;
> 
>                 HRESULT hr = lpUnk->QueryInterface(IID_IDispatch,
> 
> (LPVOID*)&lpDispatch);
> 
>                 lpUnk->Release();
> 
>                 if (hr == NOERROR)
> 
>                 {
> 
>                         m_ExcelApp.AttachDispatch(lpDispatch); // Remember IDispatch.
> 
>                         return true;
> 
>                 }
> 
>         }
> 
> 
> 
>         return false;
> 
> }
> 
> 
> 
> /Mathias
> 
> 
> 
> Den söndagen den 26:e januari 2014 kl. 15:57:31 UTC+1 skrev Jürgen Knauf:
> 
> > How do i geht the correct instance of a running Word document?
> 
> > 
> 
> > 
> 
> > 
> 
> > Exspecially when the document is opened after my vo app.

I have not startet the Word document from my application.
The user has open a word document and then he starts my programm.

I get no control to this document.

[toc] | [prev] | [next] | [standalone]


#6564

Fromdlzc <dlzc1@cox.net>
Date2014-01-27 10:52 -0800
Message-ID<eb318732-7ab4-4393-8df0-892766bc34ea@googlegroups.com>
In reply to#6563
Dear Jürgen Knauf:

On Monday, January 27, 2014 9:19:25 AM UTC-7, Jürgen Knauf wrote:
...
> I have not startet the Word document from my
> application.  The user has open a word
> document and then he starts my programm. 
> I get no control to this document.

WinAPI provides the functionality you seek.  Not sure what it named in VO:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499%28v=vs.85%29.aspx

David A. Smith

[toc] | [prev] | [next] | [standalone]


#6565

FromJürgen Knauf <trotterklaus@googlemail.com>
Date2014-01-27 12:57 -0800
Message-ID<fdd5fa23-8206-4567-8da8-fd2aff11ed0e@googlegroups.com>
In reply to#6564
Am Montag, 27. Januar 2014 19:52:42 UTC+1 schrieb dlzc:
> Dear Jürgen Knauf:
> 
> 
> 
> On Monday, January 27, 2014 9:19:25 AM UTC-7, Jürgen Knauf wrote:
> 
> ...
> 
> > I have not startet the Word document from my
> 
> > application.  The user has open a word
> 
> > document and then he starts my programm. 
> 
> > I get no control to this document.
> 
> 
> 
> WinAPI provides the functionality you seek.  Not sure what it named in VO:
> 
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499%28v=vs.85%29.aspx
> 
> 
> 
> David A. Smith
Findwindow()gives only a Window handle back.
But how can I turn this handle into an Automation Server to control the document?

[toc] | [prev] | [next] | [standalone]


#6566

FromMathias <mathias.hakansson@consultec.se>
Date2014-01-27 22:20 -0800
Message-ID<df42fbe4-fae6-43ee-967c-6626a52cc7b0@googlegroups.com>
In reply to#6565
The only way to Control the document is to get the application dispatch handle via code similar to my c++ example. The m_ExcelApp is the excel automation class and it conveniantly contains a method to assign the dispatch handle. It should be possible to translate this to VO but it will take some effort. You just have to find out what api-calls to use.

/Mathias

Den måndagen den 27:e januari 2014 kl. 21:57:51 UTC+1 skrev Jürgen Knauf:
> Am Montag, 27. Januar 2014 19:52:42 UTC+1 schrieb dlzc:
> 
> > Dear Jürgen Knauf:
> 
> > 
> 
> > 
> 
> > 
> 
> > On Monday, January 27, 2014 9:19:25 AM UTC-7, Jürgen Knauf wrote:
> 
> > 
> 
> > ...
> 
> > 
> 
> > > I have not startet the Word document from my
> 
> > 
> 
> > > application.  The user has open a word
> 
> > 
> 
> > > document and then he starts my programm. 
> 
> > 
> 
> > > I get no control to this document.
> 
> > 
> 
> > 
> 
> > 
> 
> > WinAPI provides the functionality you seek.  Not sure what it named in VO:
> 
> > 
> 
> > http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499%28v=vs.85%29.aspx
> 
> > 
> 
> > 
> 
> > 
> 
> > David A. Smith
> 
> Findwindow()gives only a Window handle back.
> 
> But how can I turn this handle into an Automation Server to control the document?

[toc] | [prev] | [next] | [standalone]


#6567

FromMathias <mathias.hakansson@consultec.se>
Date2014-01-27 22:36 -0800
Message-ID<c65ae923-ef91-4d3d-921f-2fbff23a660d@googlegroups.com>
In reply to#6566
Replying to my own messages...

CLSIDFromProgID, GetActiveObject and QueryInterface are declared in VO. You should search for these method names in the VO SDK libraries to learn how they should be used in VO.

This wasn't that hard in VO after all...

/Mathias



Den tisdagen den 28:e januari 2014 kl. 07:20:34 UTC+1 skrev Mathias:
> The only way to Control the document is to get the application dispatch handle via code similar to my c++ example. The m_ExcelApp is the excel automation class and it conveniantly contains a method to assign the dispatch handle. It should be possible to translate this to VO but it will take some effort. You just have to find out what api-calls to use.
> 
> 
> 
> /Mathias
> 
> 
> 
> Den måndagen den 27:e januari 2014 kl. 21:57:51 UTC+1 skrev Jürgen Knauf:
> 
> > Am Montag, 27. Januar 2014 19:52:42 UTC+1 schrieb dlzc:
> 
> > 
> 
> > > Dear Jürgen Knauf:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > On Monday, January 27, 2014 9:19:25 AM UTC-7, Jürgen Knauf wrote:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > ...
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > I have not startet the Word document from my
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > application.  The user has open a word
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > document and then he starts my programm. 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > I get no control to this document.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > WinAPI provides the functionality you seek.  Not sure what it named in VO:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499%28v=vs.85%29.aspx
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > David A. Smith
> 
> > 
> 
> > Findwindow()gives only a Window handle back.
> 
> > 
> 
> > But how can I turn this handle into an Automation Server to control the document?

[toc] | [prev] | [next] | [standalone]


#6568

FromMalcolm G <malcolm-news2012delete@delete.jobstream.com>
Date2014-01-28 10:10 +0000
Message-ID<tnLFu.310$Wp6.285@fx01.am4>
In reply to#6567
On 28/01/2014 06:36, Mathias wrote:
> Replying to my own messages...
> 
> CLSIDFromProgID, GetActiveObject and QueryInterface are declared in VO. You should search for these method names in the VO SDK libraries to learn how they should be used in VO.
> 
> This wasn't that hard in VO after all...

The main thing that worried me reading this thread was whether it was
possible to get the right copy (there can be more than one running excel
and I don't think getActiveObject lets you itterate all running copies
to find the one that has the open document in).

Looking at out code when we want the running word we use VOCOM but I
think it should be fairly easy to simply call the APIs above to get a
running excel.

[toc] | [prev] | [next] | [standalone]


#6569

FromMathias <mathias.hakansson@consultec.se>
Date2014-01-29 01:22 -0800
Message-ID<47d6a319-fee5-4ae2-b28b-365d700a591a@googlegroups.com>
In reply to#6568
I think there only is one running instance of excel (or Word) at any time. They can have several opened documents however, so one has to look through the list of opened documents to find the correct one.

/Mathias

Den tisdagen den 28:e januari 2014 kl. 11:10:56 UTC+1 skrev Malcolm G:
> On 28/01/2014 06:36, Mathias wrote:
> 
> > Replying to my own messages...
> 
> > 
> 
> > CLSIDFromProgID, GetActiveObject and QueryInterface are declared in VO. You should search for these method names in the VO SDK libraries to learn how they should be used in VO.
> 
> > 
> 
> > This wasn't that hard in VO after all...
> 
> 
> 
> The main thing that worried me reading this thread was whether it was
> 
> possible to get the right copy (there can be more than one running excel
> 
> and I don't think getActiveObject lets you itterate all running copies
> 
> to find the one that has the open document in).
> 
> 
> 
> Looking at out code when we want the running word we use VOCOM but I
> 
> think it should be fairly easy to simply call the APIs above to get a
> 
> running excel.

[toc] | [prev] | [next] | [standalone]


#6570

FromJürgen Knauf <trotterklaus@googlemail.com>
Date2014-01-30 22:40 -0800
Message-ID<c4e7ebaa-d638-4ce7-be14-c7736b8bdf89@googlegroups.com>
In reply to#6560
Am Sonntag, 26. Januar 2014 15:57:31 UTC+1 schrieb Jürgen Knauf:
> How do i geht the correct instance of a running Word document?
> 
> 
> 
> Exspecially when the document is opened after my vo app.

Thank you for the tipps, I will have a look on it.

[toc] | [prev] | [next] | [standalone]


#6571

FromMikeScholl@btinternet.com
Date2014-02-02 04:38 -0800
Message-ID<9bdafd29-b727-4a8a-ac16-8be350f10700@googlegroups.com>
In reply to#6570
On Friday, 31 January 2014 06:40:56 UTC, Jürgen Knauf  wrote:
> Am Sonntag, 26. Januar 2014 15:57:31 UTC+1 schrieb Jürgen Knauf:
> 
> > How do i geht the correct instance of a running Word document?
> 
> > 
> 
> > 
> 
> > 
> 
> > Exspecially when the document is opened after my vo app.
> 
> 
> 
> Thank you for the tipps, I will have a look on it.

Jurgen
You may find this useful. It's a method that creates a new word document based on a template but it doesn't open a new copy of Word if one is open already.
I imagine you can look through Word:Documents to find the one you want.
My experience of OLE with MS Office is that different versions of Office have different methods so you need to look at the VBA documentation

Mike

METHOD WriteLetter(iRec, cBaseFileName,cLetterType) CLASS BookingsShellWin
	LOCAL oWord AS OBJECT
	LOCAL oDocument AS OBJECT
	LOCAL cTemplate AS STRING
	LOCAL oWin AS LetterChooser
	LOCAL OFS AS FileSpec
	LOCAL oDlg AS SaveAsDialog
	LOCAL cPath AS STRING
	LOCAL cFilename AS STRING
	LOCAL cPrinter AS STRING
	LOCAL cDefPrinter AS STRING

	
	IF iRec > 0
		//Template chooser
		oWin := LetterChooser{SELF}
		oWin:Setup(LocalIniFS,"WordTemplates"+AllTrim(cLetterType),"BookingLetter")
		oWin:Caption := "Choose Letter Template"
		oWin:Show()
		IF oWin:Result == 1
			oFS := Filespec{oWin:FileName}
			cTemplate := oFS:FullPath
		ENDIF
		IF Empty(cTemplate)
			RETU
		ENDIF
		
		cPath := LocalIniFS:GetString("WordTemplates"+AllTrim(cLetterType),"SaveDir")
		oFS:FileName := oFS:FileName+cBaseFileName+".doc"
		oFS:Path := cPath
		oDlg := SaveasDialog{SELF,oFS:FullPath}
		oDlg:Setfilter({"*.doc"},{"Word Files"})
		oDlg:Show()
		cFileName := oDlg:FileName
		IF File(cFileName)
        	IF Textbox{,"Overwrite Existing File","File "+cFileName +" exists already",BUTTONYESNO+BOXICONQUESTIONMARK}:show() <> BOXREPLYYES
        		RETU
	        ENDIF
	    ENDIF
		//make OLE connection to Word
		oWord := OleAutoObject{"word.application"}
		oWord:visible :=TRUE
		//New document base on template	
		oDocument := oWord:Documents:Add( cTemplate, FALSE)
		//Put data into Word document
		SELF:FillBookmarks(oDocument,iRec)
		cPrinter := LocalIniFS:GetString("WordTemplates","Printer","")
		cDefPrinter := oWord:ActivePrinter
		IF cPrinter <> ""
		
			oWord:ActivePrinter := cPrinter
		ENDIF
        IF !Empty(cFileName)
	    	oDocument:SaveAs(cFileName)
	    ENDIF
		oDocument:Printout()
		oWord:ActivePrinter := cDefPrinter
    ENDIF

[toc] | [prev] | [next] | [standalone]


#6572

FromJürgen Knauf <trotterklaus@googlemail.com>
Date2014-02-03 03:42 -0800
Message-ID<315ccca3-0475-41a7-a705-675cf8152fbd@googlegroups.com>
In reply to#6571
Am Sonntag, 2. Februar 2014 13:38:34 UTC+1 schrieb MikeS...@btinternet.com:
> On Friday, 31 January 2014 06:40:56 UTC, Jürgen Knauf  wrote:
> 
> > Am Sonntag, 26. Januar 2014 15:57:31 UTC+1 schrieb Jürgen Knauf:
> 
> > 
> 
> > > How do i geht the correct instance of a running Word document?
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Exspecially when the document is opened after my vo app.
> 
> > 
> 
> > 
> 
> > 
> 
> > Thank you for the tipps, I will have a look on it.
> 
> 
> 
> Jurgen
> 
> You may find this useful. It's a method that creates a new word document based on a template but it doesn't open a new copy of Word if one is open already.
> 
> I imagine you can look through Word:Documents to find the one you want.
> 
> My experience of OLE with MS Office is that different versions of Office have different methods so you need to look at the VBA documentation
> 
> 
> 
> Mike
> 
> 
> 
> METHOD WriteLetter(iRec, cBaseFileName,cLetterType) CLASS BookingsShellWin
> 
> 	LOCAL oWord AS OBJECT
> 
> 	LOCAL oDocument AS OBJECT
> 
> 	LOCAL cTemplate AS STRING
> 
> 	LOCAL oWin AS LetterChooser
> 
> 	LOCAL OFS AS FileSpec
> 
> 	LOCAL oDlg AS SaveAsDialog
> 
> 	LOCAL cPath AS STRING
> 
> 	LOCAL cFilename AS STRING
> 
> 	LOCAL cPrinter AS STRING
> 
> 	LOCAL cDefPrinter AS STRING
> 
> 
> 
> 	
> 
> 	IF iRec > 0
> 
> 		//Template chooser
> 
> 		oWin := LetterChooser{SELF}
> 
> 		oWin:Setup(LocalIniFS,"WordTemplates"+AllTrim(cLetterType),"BookingLetter")
> 
> 		oWin:Caption := "Choose Letter Template"
> 
> 		oWin:Show()
> 
> 		IF oWin:Result == 1
> 
> 			oFS := Filespec{oWin:FileName}
> 
> 			cTemplate := oFS:FullPath
> 
> 		ENDIF
> 
> 		IF Empty(cTemplate)
> 
> 			RETU
> 
> 		ENDIF
> 
> 		
> 
> 		cPath := LocalIniFS:GetString("WordTemplates"+AllTrim(cLetterType),"SaveDir")
> 
> 		oFS:FileName := oFS:FileName+cBaseFileName+".doc"
> 
> 		oFS:Path := cPath
> 
> 		oDlg := SaveasDialog{SELF,oFS:FullPath}
> 
> 		oDlg:Setfilter({"*.doc"},{"Word Files"})
> 
> 		oDlg:Show()
> 
> 		cFileName := oDlg:FileName
> 
> 		IF File(cFileName)
> 
>         	IF Textbox{,"Overwrite Existing File","File "+cFileName +" exists already",BUTTONYESNO+BOXICONQUESTIONMARK}:show() <> BOXREPLYYES
> 
>         		RETU
> 
> 	        ENDIF
> 
> 	    ENDIF
> 
> 		//make OLE connection to Word
> 
> 		oWord := OleAutoObject{"word.application"}
> 
> 		oWord:visible :=TRUE
> 
> 		//New document base on template	
> 
> 		oDocument := oWord:Documents:Add( cTemplate, FALSE)
> 
> 		//Put data into Word document
> 
> 		SELF:FillBookmarks(oDocument,iRec)
> 
> 		cPrinter := LocalIniFS:GetString("WordTemplates","Printer","")
> 
> 		cDefPrinter := oWord:ActivePrinter
> 
> 		IF cPrinter <> ""
> 
> 		
> 
> 			oWord:ActivePrinter := cPrinter
> 
> 		ENDIF
> 
>         IF !Empty(cFileName)
> 
> 	    	oDocument:SaveAs(cFileName)
> 
> 	    ENDIF
> 
> 		oDocument:Printout()
> 
> 		oWord:ActivePrinter := cDefPrinter
> 
>     ENDIF

Mike,

but when you start your app (with closed Word) and do somethng and then start Word separately and then create a new document with an OLE-connection you will also create a new word instance.

Juergen

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web