PC Review


Reply
Thread Tools Rate Thread

Can I use VBA to copy User Form from 1 workbook to another?

 
 
=?Utf-8?B?TWlrZVp6?=
Guest
Posts: n/a
 
      31st May 2007
Title says it all...
I'm using VBA to set up a new workbook.
I want the new workbook to have stand alone macros and user forms.

I can create the user forms and macros within the workbook that I'm copying
from.

I just want to duplicate those into the new workbook.

Thanks!
 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      31st May 2007
> I'm using VBA to set up a new workbook.
> I want the new workbook to have stand alone macros and user forms.
>
> I can create the user forms and macros within the workbook that I'm
> copying
> from.
>
> I just want to duplicate those into the new workbook.


I returning to Excel after a long, long absence from it, so I am quite rusty
on many things; but, I would think you could just Export the stuff you want
from your current workbook and then Import it into the new workbook.

Rick

 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      31st May 2007
Hi Mike,

Try something like:

'=============>>
Public Sub Tester()
Dim srcWB As Workbook
Dim destWb As Workbook
Const sStr As String = "C:\myFile.frm"

Set srcWB = Workbooks("MyBook1.xls")
Set destWb = Workbooks("MyBook2.xls")

srcWB.VBProject.VBComponents("Userform1").Export _
Filename:=sStr
destWb.VBProject.VBComponents.Import _
Filename:=sStr
Kill sStr
End Sub
'<<=============

For more informatoion on exporting / importing modules,
see Chip Pearson at:

Programming To The Visual Basic Editor
http://www.cpearson.com/excel/vbe.htm


---
Regards,
Norman


"MikeZz" <(E-Mail Removed)> wrote in message
news:1E65A028-8BF0-4F2B-BCA8-(E-Mail Removed)...
> Title says it all...
> I'm using VBA to set up a new workbook.
> I want the new workbook to have stand alone macros and user forms.
>
> I can create the user forms and macros within the workbook that I'm
> copying
> from.
>
> I just want to duplicate those into the new workbook.
>
> Thanks!



 
Reply With Quote
 
=?Utf-8?B?TWlrZVp6?=
Guest
Posts: n/a
 
      1st Jun 2007
Actually I know how to do it manually. I'm looking for a way to do it in VBA
because I'm using one wb to create another and I want to send the new wb some
code and forms.

Thanks anyway.

"Rick Rothstein (MVP - VB)" wrote:

> > I'm using VBA to set up a new workbook.
> > I want the new workbook to have stand alone macros and user forms.
> >
> > I can create the user forms and macros within the workbook that I'm
> > copying
> > from.
> >
> > I just want to duplicate those into the new workbook.

>
> I returning to Excel after a long, long absence from it, so I am quite rusty
> on many things; but, I would think you could just Export the stuff you want
> from your current workbook and then Import it into the new workbook.
>
> Rick
>
>

 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      1st Jun 2007
Hi Rick,

Did the code which I suggested not work for you?


---
Regards,
Norman


"MikeZz" <(E-Mail Removed)> wrote in message
news:17E850BA-9218-4B12-AE7B-(E-Mail Removed)...
> Actually I know how to do it manually. I'm looking for a way to do it in
> VBA
> because I'm using one wb to create another and I want to send the new wb
> some
> code and forms.
>
> Thanks anyway.
>
> "Rick Rothstein (MVP - VB)" wrote:
>
>> > I'm using VBA to set up a new workbook.
>> > I want the new workbook to have stand alone macros and user forms.
>> >
>> > I can create the user forms and macros within the workbook that I'm
>> > copying
>> > from.
>> >
>> > I just want to duplicate those into the new workbook.

>>
>> I returning to Excel after a long, long absence from it, so I am quite
>> rusty
>> on many things; but, I would think you could just Export the stuff you
>> want
>> from your current workbook and then Import it into the new workbook.
>>
>> Rick
>>
>>



 
Reply With Quote
 
=?Utf-8?B?TWlrZVp6?=
Guest
Posts: n/a
 
      1st Jun 2007
OMG Norman,
This is GREAT! It's so easy!

It even works forms and I also assume sheets or any other VBObjects....
Copys the physical form as well as all the code.

Cool THANKS!

"Norman Jones" wrote:

> Hi Mike,
>
> Try something like:
>
> '=============>>
> Public Sub Tester()
> Dim srcWB As Workbook
> Dim destWb As Workbook
> Const sStr As String = "C:\myFile.frm"
>
> Set srcWB = Workbooks("MyBook1.xls")
> Set destWb = Workbooks("MyBook2.xls")
>
> srcWB.VBProject.VBComponents("Userform1").Export _
> Filename:=sStr
> destWb.VBProject.VBComponents.Import _
> Filename:=sStr
> Kill sStr
> End Sub
> '<<=============
>
> For more informatoion on exporting / importing modules,
> see Chip Pearson at:
>
> Programming To The Visual Basic Editor
> http://www.cpearson.com/excel/vbe.htm
>
>
> ---
> Regards,
> Norman
>
>
> "MikeZz" <(E-Mail Removed)> wrote in message
> news:1E65A028-8BF0-4F2B-BCA8-(E-Mail Removed)...
> > Title says it all...
> > I'm using VBA to set up a new workbook.
> > I want the new workbook to have stand alone macros and user forms.
> >
> > I can create the user forms and macros within the workbook that I'm
> > copying
> > from.
> >
> > I just want to duplicate those into the new workbook.
> >
> > Thanks!

>
>
>

 
Reply With Quote
 
Trefor
Guest
Posts: n/a
 
      2nd Jan 2009
Norman,

I tried this but I get a "Run-time error '1004': Programmatic access to
Visual Basic Project is not trusted". Do you know why?

The code is in a pw protected project, but the form I exported to a temp
folder and the new workbook where i am copying the form to is not.

--
Trefor


"Norman Jones" wrote:

> Hi Mike,
>
> Try something like:
>
> '=============>>
> Public Sub Tester()
> Dim srcWB As Workbook
> Dim destWb As Workbook
> Const sStr As String = "C:\myFile.frm"
>
> Set srcWB = Workbooks("MyBook1.xls")
> Set destWb = Workbooks("MyBook2.xls")
>
> srcWB.VBProject.VBComponents("Userform1").Export _
> Filename:=sStr
> destWb.VBProject.VBComponents.Import _
> Filename:=sStr
> Kill sStr
> End Sub
> '<<=============
>
> For more informatoion on exporting / importing modules,
> see Chip Pearson at:
>
> Programming To The Visual Basic Editor
> http://www.cpearson.com/excel/vbe.htm
>
>
> ---
> Regards,
> Norman
>
>
> "MikeZz" <(E-Mail Removed)> wrote in message
> news:1E65A028-8BF0-4F2B-BCA8-(E-Mail Removed)...
> > Title says it all...
> > I'm using VBA to set up a new workbook.
> > I want the new workbook to have stand alone macros and user forms.
> >
> > I can create the user forms and macros within the workbook that I'm
> > copying
> > from.
> >
> > I just want to duplicate those into the new workbook.
> >
> > Thanks!

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      2nd Jan 2009
This is a security setting that belongs to each user.

In xl2003 menus:
Tools|Macro|Security|Trusted publishers tab
It's a checkbox at the bottom of the dialog.


Trefor wrote:
>
> Norman,
>
> I tried this but I get a "Run-time error '1004': Programmatic access to
> Visual Basic Project is not trusted". Do you know why?
>
> The code is in a pw protected project, but the form I exported to a temp
> folder and the new workbook where i am copying the form to is not.
>
> --
> Trefor
>
> "Norman Jones" wrote:
>
> > Hi Mike,
> >
> > Try something like:
> >
> > '=============>>
> > Public Sub Tester()
> > Dim srcWB As Workbook
> > Dim destWb As Workbook
> > Const sStr As String = "C:\myFile.frm"
> >
> > Set srcWB = Workbooks("MyBook1.xls")
> > Set destWb = Workbooks("MyBook2.xls")
> >
> > srcWB.VBProject.VBComponents("Userform1").Export _
> > Filename:=sStr
> > destWb.VBProject.VBComponents.Import _
> > Filename:=sStr
> > Kill sStr
> > End Sub
> > '<<=============
> >
> > For more informatoion on exporting / importing modules,
> > see Chip Pearson at:
> >
> > Programming To The Visual Basic Editor
> > http://www.cpearson.com/excel/vbe.htm
> >
> >
> > ---
> > Regards,
> > Norman
> >
> >
> > "MikeZz" <(E-Mail Removed)> wrote in message
> > news:1E65A028-8BF0-4F2B-BCA8-(E-Mail Removed)...
> > > Title says it all...
> > > I'm using VBA to set up a new workbook.
> > > I want the new workbook to have stand alone macros and user forms.
> > >
> > > I can create the user forms and macros within the workbook that I'm
> > > copying
> > > from.
> > >
> > > I just want to duplicate those into the new workbook.
> > >
> > > Thanks!

> >
> >
> >


--

Dave Peterson
 
Reply With Quote
 
Trefor
Guest
Posts: n/a
 
      2nd Jan 2009
Dave,

Many thanks, can't believe I didn't think to check that first. I would have
set that before, is there something that would have unchecked this?


--
Trefor


"Dave Peterson" wrote:

> This is a security setting that belongs to each user.
>
> In xl2003 menus:
> Tools|Macro|Security|Trusted publishers tab
> It's a checkbox at the bottom of the dialog.
>
>
> Trefor wrote:
> >
> > Norman,
> >
> > I tried this but I get a "Run-time error '1004': Programmatic access to
> > Visual Basic Project is not trusted". Do you know why?
> >
> > The code is in a pw protected project, but the form I exported to a temp
> > folder and the new workbook where i am copying the form to is not.
> >
> > --
> > Trefor
> >
> > "Norman Jones" wrote:
> >
> > > Hi Mike,
> > >
> > > Try something like:
> > >
> > > '=============>>
> > > Public Sub Tester()
> > > Dim srcWB As Workbook
> > > Dim destWb As Workbook
> > > Const sStr As String = "C:\myFile.frm"
> > >
> > > Set srcWB = Workbooks("MyBook1.xls")
> > > Set destWb = Workbooks("MyBook2.xls")
> > >
> > > srcWB.VBProject.VBComponents("Userform1").Export _
> > > Filename:=sStr
> > > destWb.VBProject.VBComponents.Import _
> > > Filename:=sStr
> > > Kill sStr
> > > End Sub
> > > '<<=============
> > >
> > > For more informatoion on exporting / importing modules,
> > > see Chip Pearson at:
> > >
> > > Programming To The Visual Basic Editor
> > > http://www.cpearson.com/excel/vbe.htm
> > >
> > >
> > > ---
> > > Regards,
> > > Norman
> > >
> > >
> > > "MikeZz" <(E-Mail Removed)> wrote in message
> > > news:1E65A028-8BF0-4F2B-BCA8-(E-Mail Removed)...
> > > > Title says it all...
> > > > I'm using VBA to set up a new workbook.
> > > > I want the new workbook to have stand alone macros and user forms.
> > > >
> > > > I can create the user forms and macros within the workbook that I'm
> > > > copying
> > > > from.
> > > >
> > > > I just want to duplicate those into the new workbook.
> > > >
> > > > Thanks!
> > >
> > >
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      2nd Jan 2009
I've only seen it changed when I changed it.

But you could have something that changes the registry. Anything is possible
(but not probable???).

Trefor wrote:
>
> Dave,
>
> Many thanks, can't believe I didn't think to check that first. I would have
> set that before, is there something that would have unchecked this?
>
> --
> Trefor
>
> "Dave Peterson" wrote:
>
> > This is a security setting that belongs to each user.
> >
> > In xl2003 menus:
> > Tools|Macro|Security|Trusted publishers tab
> > It's a checkbox at the bottom of the dialog.
> >
> >
> > Trefor wrote:
> > >
> > > Norman,
> > >
> > > I tried this but I get a "Run-time error '1004': Programmatic access to
> > > Visual Basic Project is not trusted". Do you know why?
> > >
> > > The code is in a pw protected project, but the form I exported to a temp
> > > folder and the new workbook where i am copying the form to is not.
> > >
> > > --
> > > Trefor
> > >
> > > "Norman Jones" wrote:
> > >
> > > > Hi Mike,
> > > >
> > > > Try something like:
> > > >
> > > > '=============>>
> > > > Public Sub Tester()
> > > > Dim srcWB As Workbook
> > > > Dim destWb As Workbook
> > > > Const sStr As String = "C:\myFile.frm"
> > > >
> > > > Set srcWB = Workbooks("MyBook1.xls")
> > > > Set destWb = Workbooks("MyBook2.xls")
> > > >
> > > > srcWB.VBProject.VBComponents("Userform1").Export _
> > > > Filename:=sStr
> > > > destWb.VBProject.VBComponents.Import _
> > > > Filename:=sStr
> > > > Kill sStr
> > > > End Sub
> > > > '<<=============
> > > >
> > > > For more informatoion on exporting / importing modules,
> > > > see Chip Pearson at:
> > > >
> > > > Programming To The Visual Basic Editor
> > > > http://www.cpearson.com/excel/vbe.htm
> > > >
> > > >
> > > > ---
> > > > Regards,
> > > > Norman
> > > >
> > > >
> > > > "MikeZz" <(E-Mail Removed)> wrote in message
> > > > news:1E65A028-8BF0-4F2B-BCA8-(E-Mail Removed)...
> > > > > Title says it all...
> > > > > I'm using VBA to set up a new workbook.
> > > > > I want the new workbook to have stand alone macros and user forms.
> > > > >
> > > > > I can create the user forms and macros within the workbook that I'm
> > > > > copying
> > > > > from.
> > > > >
> > > > > I just want to duplicate those into the new workbook.
> > > > >
> > > > > Thanks!
> > > >
> > > >
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date field in user form & Loading a user form on opening workbook Balan Microsoft Excel Programming 1 24th May 2008 03:40 PM
How to copy module form one workbook to another deepakmehta Microsoft Excel Programming 4 8th May 2006 10:03 PM
Copying template to workbook but user form does not copy? Alan Ibbotson Microsoft Excel Programming 0 7th Nov 2005 11:00 PM
How do I copy a worksheet form a workbook in my workbook Neil Atkinson Microsoft Excel Programming 1 12th Oct 2005 12:23 PM
Copy VBA Module and Form from Workbook to another workbook topaiva Microsoft Excel Programming 1 25th Nov 2004 03:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:51 PM.