1

I know this is a rare question. I exported Sheet1 as .cls (because it was the only option) and when I import it, it shows up in class modules, and I cannot run them anymore. Anyways, is there a way to get the .cls file to be exported into Microsoft Excel Objects (Sheet1)?

Capture

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Brainiac
  • 75
  • 10
  • Import it as a class and then copy paste the code from the class into your desired worksheet and then delete the class. – Pᴇʜ Apr 01 '19 at 12:18
  • @Pᴇʜ Thank for your comment. I know I can do this, but I am looking maybe for a way to import it directly into Excel Objects, if there is any. – Brainiac Apr 01 '19 at 12:23
  • Direkt import is not possible in VBE. • Because the code is tied to a specific worksheet and if you import the VBE cannot know for which sheet the code is. – Pᴇʜ Apr 01 '19 at 12:24
  • Could you not modify your code so that it sits in a module and then reference is from your worksheet? – Zac Apr 01 '19 at 12:39
  • @Zac Actually that approach won't work with eg events I think (they must remain in the worksheets scope). And anything that is not an event should already be an a module anyway. – Pᴇʜ Apr 01 '19 at 13:00
  • Just import the worksheet (aka copy from original book). – AJD Apr 01 '19 at 19:16

1 Answers1

0

OK the answer to this is: There is no way to directly import VBA code into a worksheet scope in VBE.

Therefore your options are:

  • Import it as class and manually copy paste the code to the desired worksheet and delete the class afterwards
  • Import/Move the complete worksheet into your workbook. This will also include the VBA code.
  • Write your own import routine in VBA to replace the existing code in a worksheet with the one you like to import: See Copy VBA code from a Sheet in one workbook to another?

The issue here is that you have to see the worksheet and its VBA code as one union. They cannot exist separately. If you export the VBA code of a worksheet the union gets split and you cannot join them anymore (they don't know they belong to each other).

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73