Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy a userform to a different workbook with VBA

Hi there,

Does anybody know how I can copy a userform I've created in a workbook
to another workbook using VBA? As the user will be able to select the
target workbook, I need to automate this userform export with VBA.

Any ideas? Many thanks for your help!

Kuhni

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Copy a userform to a different workbook with VBA

Kuhni,

Here is an example that exports it the re-imports it

Workbooks("Book1").VBProject.VBComponents("Userfor m1").Export _
Filename:="C:\temp.frm"
Workbooks("Book3").VBProject.VBComponents.Import _
Filename:="C:\temp.frm"
Kill "C:\temp.frm"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"kuhni" wrote in message
oups.com...
Hi there,

Does anybody know how I can copy a userform I've created in a workbook
to another workbook using VBA? As the user will be able to select the
target workbook, I need to automate this userform export with VBA.

Any ideas? Many thanks for your help!

Kuhni



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy a userform to a different workbook with VBA

Bob,

Many thanks - that seems to be a very nice and easy solution for my
problem. However, I get an runtime error 1004 when adjusting your
sample code to my workbook. Are there any references needed (besides
Microsoft Visual Basic for Applications Extensibility 5.3 and the very
standard references)?

Again many thanks,
Kuhni

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Copy a userform to a different workbook with VBA

Kuhni,

Let's see your code.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"kuhni" wrote in message
ups.com...
Bob,

Many thanks - that seems to be a very nice and easy solution for my
problem. However, I get an runtime error 1004 when adjusting your
sample code to my workbook. Are there any references needed (besides
Microsoft Visual Basic for Applications Extensibility 5.3 and the very
standard references)?

Again many thanks,
Kuhni



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy a userform to a different workbook with VBA

Bob,

Sure - here it is, but it is nearly identical to your code.

1 Sub copyForm()
2 Dim targetFile As String

3 targetFile = "EK-Prices"

4 ThisWorkbook.VBProject.VBComponents("FImport").Exp ort
Filename:="C:\temp.frm"
5 Workbooks(targetFile).VBProject.VBComponents.Impor t
Filename:="C:\temp.frm"
6 Kill "C:\temp.frm"
7 End Sub

The error occurs in line 4: Runtime Error 1004.

Thanks,
Kuhni



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Copy a userform to a different workbook with VBA

Kuhni,

Just tried your code, works fine.

I don't think this is the problem as you gave line numbers, but did you put

ThisWorkbook.VBProject.VBComponents("FImport").Exp ort
Filename:="C:\temp.frm"

all on one line? Ditto 5?

Also, you should assign targetFile = "EK-Prices.xls". I didn't use that as I
had not yet saved them.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"kuhni" wrote in message
ups.com...
Bob,

Sure - here it is, but it is nearly identical to your code.

1 Sub copyForm()
2 Dim targetFile As String

3 targetFile = "EK-Prices"

4 ThisWorkbook.VBProject.VBComponents("FImport").Exp ort
Filename:="C:\temp.frm"
5 Workbooks(targetFile).VBProject.VBComponents.Impor t
Filename:="C:\temp.frm"
6 Kill "C:\temp.frm"
7 End Sub

The error occurs in line 4: Runtime Error 1004.

Thanks,
Kuhni



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
copy userform Oldjay New Users to Excel 2 November 3rd 05 02:00 AM
Copying a userform into a new workbook jase[_2_] Excel Programming 2 May 25th 05 07:56 PM
Using Userform code in a Workbook Jake8 Excel Programming 2 November 26th 04 02:21 AM
Populate Userform from another workbook Ryan Excel Programming 0 May 12th 04 09:31 PM
copy-paste in a userform Hatzipavlis Stratos Excel Programming 2 November 13th 03 10:24 AM


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

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

About Us

"It's about Microsoft Excel"