Importing Code into 'ThisWorkbook'

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I am using Excel 97.

I have a chunk of code which I need to import into
the 'ThisWorkbook' module of a workbook. It cannot be in
an 'addin' as the workbook is sent out on email and this
would mean sending the xla file with the workbook, this
would cause a lot of confusion to recipients who are
unfamiliar with EXCEL.

When I try to import it, it places it in a 'Class module'
and not the 'ThisWorkbook' part.

Can anyone assist, please?

Thanks


Mark
 
It imports it into a class module because ThisWorkbook is a class module,
and when you export it, it is exported to a .cls file. It has then lost any
reference to the specific class, and treats it as any other.

You could try AddFromFile. Save the code in a text file and use this code

ActiveWorkbook.VBProject.VBComponents("ThisWorkbook") _
.CodeModule.AddFromFile "C:\myTest\Text1.txt"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Bob,

Many thanks - it works :-)

Mark
-----Original Message-----
It imports it into a class module because ThisWorkbook is a class module,
and when you export it, it is exported to a .cls file. It has then lost any
reference to the specific class, and treats it as any other.

You could try AddFromFile. Save the code in a text file and use this code

ActiveWorkbook.VBProject.VBComponents("ThisWorkbook") _
.CodeModule.AddFromFile "C:\myTest\Text1.txt"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)




.
 
Mark,

That's good. An added benefit is that it adds, whereas import (if it worked)
is the whole thing. The problem is that you could add an event that is
already present.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top