ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with CopyModule coding (https://www.excelbanter.com/excel-programming/451059-help-copymodule-coding.html)

Ray

Help with CopyModule coding
 
Hello all!

I need to update the VBA code in a tool used by numerous people across the US and found Chip Pearson's code that would seem to solve my problem; the code is he
http://www.cpearson.com/excel/vbe.aspx

However, when I try to use it I get the following Compile Error:
Function call on left-hand side of assignment must return Variant or Object

My code looks like this:

Sub patch()

Dim VBAEditor As VBIDE.VBE
Dim ThisVBProj As VBIDE.VBProject
Dim ThatVBProj As VBIDE.VBProject

Set VBAEditor = Application.VBE
Set ThisVBProj = VBAEditor.ActiveVBProject
Set ThatVBProj = Application.Workbook("Patch Test.xlsm").VBProject

CopyModule("CODE_Clear_Tertial_Data", ThisVBProj, ThatVBProj, False) = True

End Sub

Any/all help is greatly appreciated!

Thanks,
Ray

witek

Help with CopyModule coding
 
Ray wrote:
CopyModule("CODE_Clear_Tertial_Data", ThisVBProj, ThatVBProj, False)= True



CopyModule "CODE_Clear_Tertial_Data", ThisVBProj, ThatVBProj, False


eventually

if CopyModule("CODE_Clear_Tertial_Data", ThisVBProj, ThatVBProj, False)=
True then

end if



Ray

Help with CopyModule coding
 
witek,

I appreciate the reply, but the CopyModule coding seems to be right:
-- the 'false' at the end is an "over-write existing module' setting
-- the 'true' at the end of the line (=true) is the way it needs to be called according to Chip's site

If I remove the "= True" part, I get an error of "Expected ="


witek

Help with CopyModule coding
 
Ray wrote:
witek,

I appreciate the reply, but the CopyModule coding seems to be right:
-- the 'false' at the end is an "over-write existing module' setting
-- the 'true' at the end of the line (=true) is the way it needs to be called according to Chip's site

If I remove the "= True" part, I get an error of "Expected ="



remove ( )



Ray

Help with CopyModule coding
 
Ok, removed the () ... and now it compiles, BUT throws a new error ...

" Object doesn't support this property or method" on the "Set ThatVBProj" line.

GS[_6_]

Help with CopyModule coding
 
witek,

I appreciate the reply, but the CopyModule coding seems to be right:
-- the 'false' at the end is an "over-write existing module' setting
-- the 'true' at the end of the line (=true) is the way it needs to
be called according to Chip's site

If I remove the "= True" part, I get an error of "Expected ="


Chip's example of using CopyModule works exactly as Witek suggests.
CopyModule is a function that returns a Boolean (True/False) based on
its success/failure. Your code should handle that return something
like...

If CopyModule Then 'success
'do this
Else 'failure
'do that
End if

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



isabelle

Help with CopyModule coding
 
hi Ray,

do you added a reference to the VBA Extensibility library ?

isabelle

Le 2015-08-28 11:23, Ray a écrit :
Ok, removed the () ... and now it compiles, BUT throws a new error ...

" Object doesn't support this property or method" on the "Set ThatVBProj" line.


GS[_6_]

Help with CopyModule coding
 
hi Ray,

do you added a reference to the VBA Extensibility library ?

isabelle

Le 2015-08-28 11:23, Ray a écrit :
Ok, removed the () ... and now it compiles, BUT throws a new error
...

" Object doesn't support this property or method" on the "Set
ThatVBProj" line.


Good question! I ass-u-me'd he read Chip's article and thus *followed
the instructions within*!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



isabelle

Help with CopyModule coding
 

Le 2015-08-28 18:03, GS a écrit :
Good question! I ass-u-me'd he read Chip's article and thus *followed the
instructions within*!


hi Garry,

sometimes, i do zigzag reading, so...

isabelle


All times are GMT +1. The time now is 06:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com