K
kalbrecht1972_hotmail_com
I am able to add code modules to excel, creating Excel macros via VBScript.
Is it possible to add Excel Userforms the same way? Here is my code below:
Dim Code, objXL, Workbook, Worksheet, Macros dim oFSO, oFile,f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fspenTextFile("c:\KFA\Book1.txt", ForReading) 'Read the text file
Code = f.Read(1500)'1500 denotes the number of characters
Set objXL = CreateObject("Excel.Application")
Set Workbook = objXL.Workbooks.Open("C:\KFA\BOOK1.XLS")
Set Worksheet = Workbook.Sheets(1)
'Add ref to macro position
Set Macros = Workbook.VBProject.VBComponents(1).CodeModule
'Add new macro; AddFromFile is also an option
Macros.AddFromString Code
' Save the result
objXL.Save
Set objXL = Nothing
Is it possible to add Excel Userforms the same way? Here is my code below:
Dim Code, objXL, Workbook, Worksheet, Macros dim oFSO, oFile,f
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fspenTextFile("c:\KFA\Book1.txt", ForReading) 'Read the text file
Code = f.Read(1500)'1500 denotes the number of characters
Set objXL = CreateObject("Excel.Application")
Set Workbook = objXL.Workbooks.Open("C:\KFA\BOOK1.XLS")
Set Worksheet = Workbook.Sheets(1)
'Add ref to macro position
Set Macros = Workbook.VBProject.VBComponents(1).CodeModule
'Add new macro; AddFromFile is also an option
Macros.AddFromString Code
' Save the result
objXL.Save
Set objXL = Nothing