HI,
Is there any way by which an existing module in another excel book be copied / inserted in active workbook.
Please suggest if any.
HI,
Is there any way by which an existing module in another excel book be copied / inserted in active workbook.
Please suggest if any.
You could save the module in the other workbook, assumig it is open, then import that
[vba]
Workbooks("Book1").VBProject.VBComponents("Module1").Export "C:\myMod.txt"
ThisWorkbook.VBProject.VBComponents.Import "C:\myMod.txt"
Kill "c:\myMod.txt"
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
I believe you cannot write a new file to the root directory in Vista, and in testing this code, this seems to be confirmed. The following adjustment works
[vba]
Workbooks("Book1").VBProject.VBComponents("Module1").Export "C:\AAA\myMod.txt"
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
As it used regulalry, best to setup a variable
[vba]
Const tempFile as string = "C:\temp\myMod.txt"
Workbooks("Book1").VBProject.VBComponents("Module1").Export tempFile
ThisWorkbook.VBProject.VBComponents.Import tempFile
Kill tempFile
[/vba]
I definitely need to setup a Vista VM!
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Hi All,
Thanks a lot.
Bob,
Thanks for the brilliant idea
Regards
Sai