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

Is there a means by which one can direct imported code into a sheet
module?

Thanks,
John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Import into a Sheet module

Hi John

See Chip's site
http://www.cpearson.com/excel/vbe.htm

--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message ups.com...
Is there a means by which one can direct imported code into a sheet
module?

Thanks,
John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Import into a Sheet module

Chip's site is excellent, but it doesn't address how to import into a
sheet module. I am creating a sheet via VBA and I need to place code
in the sheet module. The amount of code needed precludes the use of
Chip's "Adding a Procedure to a Module" routine. Rather, I have the
code in a regular module with hopes of exporting and importing to the
new sheet module.

Thanks,
John

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Import into a Sheet module

You can use this for a sheet module

Sub AddProceduretosheet()
Dim VBCodeMod As CodeModule
Dim LineNum As Long

Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("sheet1").Code Module
With VBCodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, _
"Sub MyNewProcedure()" & Chr(13) & _
" Msgbox ""Here is the new procedure"" " & Chr(13) & _
"End Sub"
End With
End Sub

Sub DeleteProcedurefromsheet()
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long

Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("sheet1").Code Module
With VBCodeMod
StartLine = .ProcStartLine("MyNewProcedure", vbext_pk_Proc)
HowManyLines = .ProcCountLines("MyNewProcedure", vbext_pk_Proc)
.DeleteLines StartLine, HowManyLines
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message oups.com...
Chip's site is excellent, but it doesn't address how to import into a
sheet module. I am creating a sheet via VBA and I need to place code
in the sheet module. The amount of code needed precludes the use of
Chip's "Adding a Procedure to a Module" routine. Rather, I have the
code in a regular module with hopes of exporting and importing to the
new sheet module.

Thanks,
John



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Import into a Sheet module

Yes, that is the method from Chip's page I referenced. That method
seems a bit tedious, IMHO, for adding 389 lines of code to the sheet
module. Thus, I would like to import the code from another location.

Thanks,
John



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Import into a Sheet module

Maybe : Import the code from a txt file

Sub AddcodefromTXTfile()
Dim VBComp As VBComponent
Application.VBE.ActiveVBProject.VBComponents.Item( "Sheet1") _
..CodeModule.AddFromFile ("C:\Code.txt")
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message oups.com...
Yes, that is the method from Chip's page I referenced. That method
seems a bit tedious, IMHO, for adding 389 lines of code to the sheet
module. Thus, I would like to import the code from another location.

Thanks,
John



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Import into a Sheet module

I inserted a Sheet1 and created c:\code.txt and the sub worked great.
My sincere thanks to you....I'm almost there.

But when I change the item name to the sheet I am using ("Activities")
I get a "Subscript out of range" error. The sheet exists, is not
protected, and has an empty module. I think that error typically means
that the referenced sheet does not exist.

Any ideas?

Thanks,
John

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Import into a Sheet module

Hi John

It use the code name and not the sheet name on the tab
If you are in the VBA editor and select a sheet and press F4 you can change the code name

--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message oups.com...
I inserted a Sheet1 and created c:\code.txt and the sub worked great.
My sincere thanks to you....I'm almost there.

But when I change the item name to the sheet I am using ("Activities")
I get a "Subscript out of range" error. The sheet exists, is not
protected, and has an empty module. I think that error typically means
that the referenced sheet does not exist.

Any ideas?

Thanks,
John



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Import into a Sheet module

Ok. Can I set the code name when I create the sheet?

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Import into a Sheet module

I think it is easier to do this for you

1) open a new workbook
2) delete all sheets except one
3) Add all the code you want in this sheet
4) FileSaveAs choose Template in Save as Type and save the file

Then with code you can insert the sheet with the code in one step
Sheets.Add Type:="C:\templatetest.xlt"






--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message oups.com...
Ok. Can I set the code name when I create the sheet?





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Import into a Sheet module

If you save it the template folder then you can use this

Sheets.Add Type:=Application.TemplatesPath & "\templatetest.xlt"

Also easy to insert it manual then (right click on a sheet tab and choose insert)


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
I think it is easier to do this for you

1) open a new workbook
2) delete all sheets except one
3) Add all the code you want in this sheet
4) FileSaveAs choose Template in Save as Type and save the file

Then with code you can insert the sheet with the code in one step
Sheets.Add Type:="C:\templatetest.xlt"






--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message oups.com...
Ok. Can I set the code name when I create the sheet?





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
Remove and Import Module Richard Excel Programming 1 September 2nd 05 09:18 AM
Calls from sheet module to ThisWorkbook module quartz[_2_] Excel Programming 2 June 23rd 05 03:37 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
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 12:39 AM.

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

About Us

"It's about Microsoft Excel"