Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Show userform from another workbook

I have a database of items in another workbook. I need to select certain
items from the database to use in the current workbook using a listbox. Does
it make a difference which workbook I put the userform in? What is the proper
code to load and show a userform from another workbook or if the userform is
in the currentworkbook how do I set the rowsource for the listbox when the
rowsource is in another workboo?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Show userform from another workbook

You can put the userform in the workbook where it belongs.

And if the userform belongs in a different workbook (say book1.xls), you can add
a subroutine into book1.xls's project that shows the userform:

(In a general module)
Option Explicit
Sub ShowMyForm()
UserForm1.Show
End Sub

You can use this kind of code to populate the listbox from the activesheet--no
matter what workbook is active.

(this goes behind the userform in book1.xls)
Option Explicit
Private Sub UserForm_Initialize()
Me.ListBox1.RowSource = ActiveSheet.Range("A1:A10").Address(external:=True )
End Sub


And to show that userform in book1.xls using code in a different workbook, you
could use code like:

Option Explicit
Sub testme()
Dim OtherWkbk As Workbook
Set OtherWkbk = Workbooks("book1.xls")
Application.Run "'" & OtherWkbk.Name & "'!showmyform"
End Sub

=======
Personally, I would think about keeping the data (in the database) in a separate
workbook. Then put the userform code into an addin, create a toolbar for that
addin that shows the userform and never put the code in those other "source"
workbooks.




ranswrt wrote:

I have a database of items in another workbook. I need to select certain
items from the database to use in the current workbook using a listbox. Does
it make a difference which workbook I put the userform in? What is the proper
code to load and show a userform from another workbook or if the userform is
in the currentworkbook how do I set the rowsource for the listbox when the
rowsource is in another workboo?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Show userform from another workbook

Thank you I'll work on that.

"Dave Peterson" wrote:

You can put the userform in the workbook where it belongs.

And if the userform belongs in a different workbook (say book1.xls), you can add
a subroutine into book1.xls's project that shows the userform:

(In a general module)
Option Explicit
Sub ShowMyForm()
UserForm1.Show
End Sub

You can use this kind of code to populate the listbox from the activesheet--no
matter what workbook is active.

(this goes behind the userform in book1.xls)
Option Explicit
Private Sub UserForm_Initialize()
Me.ListBox1.RowSource = ActiveSheet.Range("A1:A10").Address(external:=True )
End Sub


And to show that userform in book1.xls using code in a different workbook, you
could use code like:

Option Explicit
Sub testme()
Dim OtherWkbk As Workbook
Set OtherWkbk = Workbooks("book1.xls")
Application.Run "'" & OtherWkbk.Name & "'!showmyform"
End Sub

=======
Personally, I would think about keeping the data (in the database) in a separate
workbook. Then put the userform code into an addin, create a toolbar for that
addin that shows the userform and never put the code in those other "source"
workbooks.




ranswrt wrote:

I have a database of items in another workbook. I need to select certain
items from the database to use in the current workbook using a listbox. Does
it make a difference which workbook I put the userform in? What is the proper
code to load and show a userform from another workbook or if the userform is
in the currentworkbook how do I set the rowsource for the listbox when the
rowsource is in another workboo?


--

Dave Peterson

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
show userform/hide workbook pswanie Excel Programming 7 January 19th 08 04:39 PM
Userform Show Noemi Excel Programming 3 September 7th 06 12:17 AM
How to load/show UserForm from other Workbook [email protected] Excel Programming 1 July 22nd 06 01:23 PM
show userform john tempest[_2_] Excel Programming 5 May 12th 06 06:07 PM
How to Show a userform from XLA sub Thibault Excel Programming 1 December 8th 03 03:36 PM


All times are GMT +1. The time now is 02:59 PM.

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

About Us

"It's about Microsoft Excel"