ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating new VBA code on the fly (https://www.excelbanter.com/excel-programming/291111-creating-new-vba-code-fly.html)

Jag Man

Creating new VBA code on the fly
 
I am writing an Excel/VBA application in which it would be helpful
to construct a new VBA module 'on the fly," i.e, so
it could be used in the same application later. I've previously used
InsertLines to create an event procedure for a control button click
on a worksheet, so that is one possibility if I can figure out
the details. How would I indicate Which module to put it in?


Another possibility is to write the code to a file, then
import the file as a module. Is importing possible programmatically,
or only from the File menu in the VBA IDE?

TIA



Vasant Nanavati

Creating new VBA code on the fly
 
Chip Pearson shows you how:

http://www.cpearson.com/excel/vbe.htm

--

Vasant


"Jag Man" wrote in message
...
I am writing an Excel/VBA application in which it would be helpful
to construct a new VBA module 'on the fly," i.e, so
it could be used in the same application later. I've previously used
InsertLines to create an event procedure for a control button click
on a worksheet, so that is one possibility if I can figure out
the details. How would I indicate Which module to put it in?


Another possibility is to write the code to a file, then
import the file as a module. Is importing possible programmatically,
or only from the File menu in the VBA IDE?

TIA





Rob van Gelder[_4_]

Creating new VBA code on the fly
 
Sub test()
Dim wkb As Workbook

Set wkb = ThisWorkbook 'as an example

wkb.VBProject.VBComponents.Import "C:\T\Module2.bas"
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Jag Man" wrote in message
...
I am writing an Excel/VBA application in which it would be helpful
to construct a new VBA module 'on the fly," i.e, so
it could be used in the same application later. I've previously used
InsertLines to create an event procedure for a control button click
on a worksheet, so that is one possibility if I can figure out
the details. How would I indicate Which module to put it in?


Another possibility is to write the code to a file, then
import the file as a module. Is importing possible programmatically,
or only from the File menu in the VBA IDE?

TIA






All times are GMT +1. The time now is 12:15 PM.

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