Run Time Error '1004' when displaying userform

flipcube

Board Regular
Joined
Aug 29, 2011
Messages
134
Hi all,

trying to display userform2 located in Book2.xlsm from a command button located in Book1.xlsm

here is my code:

Book2 code...

Sub Z()
userform 2.show
End sub

Book1 code...

Sub commandbutton1_click()
Application.Run "'Book2.xlsm'!Z"
end sub

both workbooks are open.

I get a Run Time Error '1004': Cannot run the macro "'Book2.xlsm'!Z". the macro may not be available in this workbook or all macros are disabled.

I've done some searching online and cannot understand why i am getting the error.

I'm wondering if it has something to do with the .xlsm extension

Thanks.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

flipcube

Board Regular
Joined
Aug 29, 2011
Messages
134
Space between useform and 2 is a typo when I posted. it is not there in the actual VB code
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,958
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
For me it works perfectly in my test.

Is Book2.xlsm the correct name? Is that file saved?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,282
Office Version
  1. 365
Platform
  1. Windows
Are both workbooks saved?
 

flipcube

Board Regular
Joined
Aug 29, 2011
Messages
134

ADVERTISEMENT

Wigi, Norie,

yes, both files are saved and located in the same folder. I went home last night and tested it on Excel 2003 and it worked just fine. I tried it again this morning at work (Excel 2007) and it also worked.

I did not change anything from yesterday...operator error I guess.

Thanks
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,958
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Okay, fine, thanks for confirmation.
 

flipcube

Board Regular
Joined
Aug 29, 2011
Messages
134

ADVERTISEMENT

Hi all,

It seems that now I have the same issue as described above. I moved the respective workbooks from my H: drive onto one of my company's shared drives and now I am getting the same problem described above.

nothing has changed except the file locations. any ideas what could be causing the error now?

Thanks,
Flipcube
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,282
Office Version
  1. 365
Platform
  1. Windows
Are both workbooks open?
 

taurean

Well-known Member
Joined
Jun 17, 2011
Messages
2,181
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
How are the macro enabling settings defined?

From your description, it seems as if in the macro settings:
Excel Options >> Trust Center >> Trust Center Settings >> Macro Settings
are different for Local Drives and Network Drives.
That is: Local Drives are added as Trusted Locations and Network Drives aren't.

So the workbook opened needs to be macro enabled before executing this code.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,685
Messages
5,637,809
Members
416,983
Latest member
LessThanAverageUser

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top