ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm1.show fails if another workbook is open (https://www.excelbanter.com/excel-programming/365275-userform1-show-fails-if-another-workbook-open.html)

Gary

UserForm1.show fails if another workbook is open
 
If I have two excel files (both with VBA applications) open and I am running
VBA application from one of them, when I try to do €śUser1.show€ť, it fails. I
get a €śRun Time error 9. Subscript out of range.€ť

However if I close the application I am not using at the moment the
€śUser1.Show €ś works as expected.

Any help would be appreciated,

Gary


Leith Ross[_596_]

UserForm1.show fails if another workbook is open
 

Hello Gary,

When 2 or more Workbooks are open and running VBA it is important to
use fully qualified object references. You can have 2 UserForm1 forms
declared. You have to tell Excel which form you want by qualifying the
reference with the workbook it belongs to.

Example:
Workbooks("Book1").UserForm1.Show

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=555233


Gary

UserForm1.show fails if another workbook is open
 
Leith,

Thanks for your response. It makes sense, but when I tried:

myworkbook = ThisWorkbook.Name ' shows current workbook in debugger

Workbook(myworkbook).UserForm1.show ' compile error !

I got "sub or Function not defiend error"

Any ideas ?

Gary

"Leith Ross" wrote:


Hello Gary,

When 2 or more Workbooks are open and running VBA it is important to
use fully qualified object references. You can have 2 UserForm1 forms
declared. You have to tell Excel which form you want by qualifying the
reference with the workbook it belongs to.

Example:
Workbooks("Book1").UserForm1.Show

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=555233



Leith Ross[_601_]

UserForm1.show fails if another workbook is open
 

ello Gary,

You need to use the SET statement to define your object reference...

Dim MyWorkbook As Workbook
Set MyWorkbook = ThisWorkbook

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=555233



All times are GMT +1. The time now is 09:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com