Issue 111144 - Can't call Sheet module's function by Sheet object in VBA
Summary: Can't call Sheet module's function by Sheet object in VBA
Status: CLOSED FIXED
Alias: None
Product: App Dev
Classification: Unclassified
Component: vba (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Trivial
Target Milestone: ---
Assignee: ab
QA Contact: noel.power
URL:
Keywords:
Depends on:
Blocks: 111505
  Show dependency tree
 
Reported: 2010-04-26 07:22 UTC by lihuiibm
Modified: 2017-05-20 09:32 UTC (History)
2 users (show)

See Also:
Issue Type: PATCH
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Test sample for this issue (29.50 KB, text/plain)
2010-04-26 08:35 UTC, lihuiibm
no flags Details
Did a little change based on noel's fix (9.27 KB, text/plain)
2010-04-30 08:55 UTC, lihuiibm
no flags Details
the old patch (22.66 KB, text/plain)
2010-05-11 14:08 UTC, noel.power
no flags Details
new version of the patch ( assumes the previous version doesn't exist ) (65.64 KB, patch)
2010-05-11 14:15 UTC, noel.power
no flags Details | Diff
more missing places to hook in a sheet module as parent (73.32 KB, text/plain)
2010-05-11 17:25 UTC, noel.power
no flags Details
more missing places where parent for range needs to be set ( and replacement of getParent calls ) (83.42 KB, patch)
2010-05-11 22:04 UTC, noel.power
no flags Details | Diff
next version ( includes fall back for access of sheets in other workbook ) (22.66 KB, patch)
2010-05-12 16:01 UTC, noel.power
no flags Details | Diff
this time the real updated patch ( with sheets fallback ) (84.22 KB, patch)
2010-05-12 16:28 UTC, noel.power
no flags Details | Diff
new iteration with code to create the document modules in a new workbook ( from api ) (91.77 KB, patch)
2010-05-13 15:46 UTC, noel.power
no flags Details | Diff
add one last missing set of parent for a range (92.22 KB, patch)
2010-05-13 16:29 UTC, noel.power
no flags Details | Diff
more tweaks ( here fix some erroneous project name handling ) - all of this untested of course ;-) (92.19 KB, patch)
2010-05-18 18:26 UTC, noel.power
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description lihuiibm 2010-04-26 07:22:07 UTC
Can't call Sheet module's function by Sheet object, such as: Sheets(2).Hello
"World", "Hello" is a function defined in module Sheet2. Please try the attached
sample file.
Comment 1 lihuiibm 2010-04-26 08:35:54 UTC
Created attachment 69105 [details]
Test sample for this issue
Comment 2 noel.power 2010-04-26 13:45:38 UTC
yep, known problem....
Currently I am looking at this issue and think it can be fixed by a cheap and
nasty hack, lets see if it works
Comment 3 noel.power 2010-04-26 22:34:54 UTC
got some small success accessing ( from basic->apiobject->module-method ) at
least for simple methods ( no support for params yet ), trying to get the same
thing working for properties, then will support properties and after that need
to clean up the patch a little
Comment 4 noel.power 2010-04-26 22:36:22 UTC
>then will support properties and after that ....
of course I mean "then will support params.." e.g. methods with paramaters 
Comment 5 noel.power 2010-04-28 15:44:34 UTC
adding a temporary patch, this patch allows the Worksheet api object to expose
the methods, properties and variables of the associated document object via uno.
This is sort of an inside out solution which allows the api object to access &
expose the associated basic module data. This means when you access a document
api object ( like the activesheet ) in a macro and you can also access any data
or procedure in document sheet basic module associated with that api object (
see attached document for an example ).
* Note: this patch only address the Worksheet object, the same technique will
work ( not done yet )
* Note: I am working on the real solution which would allow the Module itself (
including access to the api object ) to be exported as an uno object. 
Comment 6 noel.power 2010-04-28 15:49:33 UTC
>* Note: this patch only address the Worksheet object...
should read
 Note: this patch only address the Worksheet object, the same applies to the
Workbook object
Comment 7 lihuiibm 2010-04-30 08:55:17 UTC
noel, thank you very much for your fix for this issue, I tried, it works well.
And I did a little changes based on your fix(vbadocmodule.hxx and
vbadocmodule.cxx), please take a look at my changes:
1. Remove the variables from vbadocmodule.hxx:
SbMethodRef mpMethod
SbPropertyRef mpProperty
And add two method: 
SbMethodRef getMethod( const rtl::OUString& aName ) throw
(com::sun::star::uno::RuntimeException)
SbPropertyRef getProperty( const rtl::OUString& aName ) throw
(com::sun::star::uno::RuntimeException)

2. hasMethod(...) and hasProperty(...) will call getMethod(...) and
getProperty(...).

Please take a look at the changes, thanks!
Comment 8 lihuiibm 2010-04-30 08:55:50 UTC
Created attachment 69178 [details]
Did a little change based on noel's fix
Comment 9 noel.power 2010-05-04 10:52:40 UTC
the changes look good to me, I think my attempt at some cheap caching of the
method(s)/property(s) was a little optimistic anyway. On the other hand I don't
intend to keep this implementation, like I said we really need to make the
module itself be able to be represented as an uno object ( and I am currently
working on that )
Comment 10 noel.power 2010-05-11 14:08:22 UTC
Created attachment 69416 [details]
the old patch
Comment 11 noel.power 2010-05-11 14:15:45 UTC
Created attachment 69417 [details]
new version of the patch ( assumes the previous version doesn't exist )
Comment 12 noel.power 2010-05-11 14:22:34 UTC
still it looks like there is far too much accuire/release of the new object, I
suspect that every single object that has a Parent object in its ctor needs the
signature changed e.g.

* old 
   AnApiObject( const uno::Reference< XHelperInterface >&, ... )
* new
   AnApiObject( const uno::WeakReference< XHelperInterface >&, ... )

hopefully that will ensure that the attempting to convert WeakReference to
Reference only be attempted when GetParent() is called ( additionally internally
GetParent() shouldn't be called for objects whose parent is a Document Reference
( because these objects should always be in scope and ideally we should be able
just use the WeakReference directly ) 

Comment 13 noel.power 2010-05-11 17:25:22 UTC
Created attachment 69421 [details]
more missing places to hook in a sheet module as parent
Comment 14 noel.power 2010-05-11 22:04:36 UTC
Created attachment 69425 [details]
more missing places where parent for range needs to be set ( and replacement of getParent calls )
Comment 15 noel.power 2010-05-12 16:01:55 UTC
Created attachment 69434 [details]
next version ( includes fall back for access of sheets in other workbook )
Comment 16 noel.power 2010-05-12 16:28:44 UTC
Created attachment 69435 [details]
this time the real updated patch ( with sheets fallback )
Comment 17 noel.power 2010-05-13 15:46:30 UTC
Created attachment 69447 [details]
new iteration with code to create the document modules in a new workbook ( from api )
Comment 18 noel.power 2010-05-13 15:50:02 UTC
last patch is as they say... "getting there", still some duplication of code
that I am not happy about, additionally need to check if the acuire/release
storm can be calmed by using WeakReference in ctors.
Comment 19 noel.power 2010-05-13 16:29:28 UTC
Created attachment 69448 [details]
add one last missing set of parent for a range
Comment 20 noel.power 2010-05-18 18:26:06 UTC
Created attachment 69521 [details]
more tweaks ( here fix some erroneous project name handling ) - all of this untested of course ;-)
Comment 21 ab 2010-07-05 13:03:37 UTC
Make me owner...
Comment 22 ab 2010-07-05 13:04:28 UTC
-> OOo 3.3, FIXED
Comment 23 noel.power 2010-07-05 13:15:05 UTC
.
Comment 24 michael.brauer 2010-08-02 14:00:28 UTC
Verified in CWS mib17