Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Import module

I need my VBA to import a module depending on certain conditions.

Problem is that the project is 'hidden from viewing' with a code, and
apparrently this also blocks for modules to be imported!

Is there a way to temporary unlock the project, import the module, and then
protect the project again?

I'm not talking about cracking the project - the code is known...

....just need to temporary allow for a module to be imported by VBA code (the
importing code, I already know :-)


Thanks in advance...


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default Import module

There's nothing built into excel/VBA that allows you to unprotect a protected
project.

You may be able to search google for techniques that use Sendkeys, but I
wouldn't use anything that is as unreliable as that.



On 07/03/2011 04:34, Charlotte E wrote:
I need my VBA to import a module depending on certain conditions.

Problem is that the project is 'hidden from viewing' with a code, and
apparrently this also blocks for modules to be imported!

Is there a way to temporary unlock the project, import the module, and then
protect the project again?

I'm not talking about cracking the project - the code is known...

...just need to temporary allow for a module to be imported by VBA code (the
importing code, I already know :-)


Thanks in advance...



--
Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default Import module

hi,

Sub TestUnprotectVBA()
'the password = "a"
Workbooks.Open Filename:="C:\temp\MyFile.xls"
Call UnprotectVBProject(ActiveWorkbook, "a")
End Sub

Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
Dim vbProj As Object
Set vbProj = WB.VBProject
If vbProj.Protection < 1 Then Exit Sub
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Password & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8, _
recursive:=True).Execute
End Sub


--
isabelle

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Import module

Charlotte E wrote :
I need my VBA to import a module depending on certain conditions.

Problem is that the project is 'hidden from viewing' with a code, and
apparrently this also blocks for modules to be imported!

Is there a way to temporary unlock the project, import the module, and then
protect the project again?

I'm not talking about cracking the project - the code is known...

...just need to temporary allow for a module to be imported by VBA code (the
importing code, I already know :-)


Thanks in advance...


Is there some reason the module can't be included in the project and
only use its code under certain conditions?

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Import module

Is there some reason the module can't be included in the project and only
use its code under certain conditions?


It contains XL2007 code, which won't complie under XL2003 - so, I check for
Application.Version, and import the module if Version is 11.

Works like a charm :-)
Unless if project is hidden from viewing :-(

CE

"GS" wrote in message ...
Charlotte E wrote :
I need my VBA to import a module depending on certain conditions.

Problem is that the project is 'hidden from viewing' with a code, and
apparrently this also blocks for modules to be imported!

Is there a way to temporary unlock the project, import the module, and
then protect the project again?

I'm not talking about cracking the project - the code is known...

...just need to temporary allow for a module to be imported by VBA code
(the importing code, I already know :-)


Thanks in advance...


Is there some reason the module can't be included in the project and only
use its code under certain conditions?

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Import module

Thanks - I'll look at it tonight when I back :-)

CE


"isabelle" wrote in message ...
hi,

Sub TestUnprotectVBA()
'the password = "a"
Workbooks.Open Filename:="C:\temp\MyFile.xls"
Call UnprotectVBProject(ActiveWorkbook, "a")
End Sub

Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
Dim vbProj As Object
Set vbProj = WB.VBProject
If vbProj.Protection < 1 Then Exit Sub
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Password & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=257 8, _
recursive:=True).Execute
End Sub


--
isabelle



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Import module

"Charlotte E" wrote in message
...
Is there some reason the module can't be included in the project and
only use its code under certain conditions?


It contains XL2007 code, which won't complie under XL2003 - so, I
check for Application.Version, and import the module if Version is
11.

Works like a charm :-)
Unless if project is hidden from viewing :-(


Sounds to me like a place for conditional compiler code ... no time to
pull up an example just now; reply if you want more information. Open
up the VBE and enter conditional compile in the help box.

--
Clif


CE

"GS" wrote in message
...
Charlotte E wrote :
I need my VBA to import a module depending on certain conditions.

Problem is that the project is 'hidden from viewing' with a code,
and apparrently this also blocks for modules to be imported!

Is there a way to temporary unlock the project, import the module,
and then protect the project again?

I'm not talking about cracking the project - the code is known...

...just need to temporary allow for a module to be imported by VBA
code (the importing code, I already know :-)


Thanks in advance...


Is there some reason the module can't be included in the project and
only use its code under certain conditions?

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc







--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Import module

Charlotte E brought next idea :
Is there some reason the module can't be included in the project and only
use its code under certain conditions?


It contains XL2007 code, which won't complie under XL2003 - so, I check for
Application.Version, and import the module if Version is 11.

Works like a charm :-)
Unless if project is hidden from viewing :-(

CE

"GS" wrote in message ...
Charlotte E wrote :
I need my VBA to import a module depending on certain conditions.

Problem is that the project is 'hidden from viewing' with a code, and
apparrently this also blocks for modules to be imported!

Is there a way to temporary unlock the project, import the module, and
then protect the project again?

I'm not talking about cracking the project - the code is known...

...just need to temporary allow for a module to be imported by VBA code
(the importing code, I already know :-)


Thanks in advance...


Is there some reason the module can't be included in the project and only
use its code under certain conditions?

-- Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc



Ok. So what I do is make a 'plugin' addin to my addin, so if your
'core' addin detects =XL12 then open the 'plugin' addin and have its
menus added to yours. This will allow you to use Workbooks.Open as
normal, and you can store the xlam in the same folder as your xla.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Import module

Charlotte,

It contains XL2007 code, which won't complie under XL2003 - so, I check
for Application.Version, and import the module if Version is 11.


If the prohect is locked it's tricky to lock & relock. It can be done
without SendKeys but overkill for your purposes. Even if the project is not
locked User's security settings will need to "trust access to VBProject"

There are workarounds, it depends what you are doing but the simplest is
don't fully declare any objects that prefix later version stuff, eg

Dim rng as Range, oRng as Object

If vers <=11 then
set rng = rng.2003-stuff
Else
Set oRng = oRng.2007/2010-stuff
Set rng = oRng
End if

That's contrived just for ideas, maybe different procedures for 2003 / 2007.

Clif,

Sounds to me like a place for conditional compiler code ... no time to
pull up an example just now; reply if you want more information. Open up
the VBE and enter conditional compile in the help box.


Problem is you can't change the conditional arguments after distributing
without access to the project, in effect back to square one.

Peter Thornton

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Import module

"Peter T" wrote in message
...
Charlotte,

It contains XL2007 code, which won't complie under XL2003 - so, I
check for Application.Version, and import the module if Version is
11.


[ ]

Clif,

Sounds to me like a place for conditional compiler code ... no time
to pull up an example just now; reply if you want more information.
Open up the VBE and enter conditional compile in the help box.


Problem is you can't change the conditional arguments after
distributing without access to the project, in effect back to square
one.

Peter Thornton



Ahh .. I see my error now. In my haste I <conveniently forgot that
conditional directives can test only constants or literals. Thanks for
the catch!

--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
import existing module JNW Excel Programming 10 May 18th 07 10:28 PM
Import Module to New Workbook Z-Excel Excel Programming 0 January 17th 07 11:43 PM
Import Module [email protected] Excel Programming 0 August 7th 06 09:11 PM
Import useerfom, module in .xlt Raymond[_7_] Excel Programming 0 January 21st 04 01:00 PM
Import module with vba sandy98 Excel Programming 2 November 13th 03 03:18 PM


All times are GMT +1. The time now is 02:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"