Link to home
Start Free TrialLog in
Avatar of Noah
NoahFlag for Singapore

asked on

Error With Running A Userform in A Different Workbook

Greetings Experts,

I have two excel Macro enabled workbooks, however, I have a userform in one workbook called "PART 1 - REFRESH COPY & PASTE" and I need to run the userform in another workbook called "example".

PART-1---REFRESH-COPY---PASTE.xlsm
example.xlsm

I was provided this code previously:
Sub ShowForm()
    Application.Run "'" & ThisWorkbook.Path & "\PART-1---REFRESH-COPY---PASTE.xlsm'!OpenForm"
End Sub

Open in new window


However, I keep getting this error and I have already allowed the file path under trust center
User generated image
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

you probably pointing the file wrongly? I guess you should try:

Application.Run "'" & ThisWorkbook.Path & "\PART 1 - REFRESH COPY & PASTE.xlsm'!OpenForm"

since the userform is in PART 1 - REFRESH COPY & PASTE.xlsm and not in PART-1---REFRESH-COPY---PASTE.xlsm

try to name your files differently with proper meaning.
Avatar of Noah

ASKER

I have already tried that as well
Avatar of Noah

ASKER

That's why in the error picture, it shows that PART 1 - REFRESH COPY & PASTE macro cannot be run
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Noah

ASKER

I still get the same error
Avatar of Noah

ASKER

Is it possible to export(copy and paste) an entire userform from one workbook into another workbook?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is it possible to export(copy and paste) an entire userform from one workbook into another workbook?
Yes. In Visual Basic, right-click on the userform file name and choose 'Export'. Then in the target workbook in Visual Basic go to the menu and select File->Import and find the exported file.
Avatar of Noah

ASKER

Oh it works now! Thanks so much for your help:)))))
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And in the post where I mentioned bolded, make sure that there's a double quote and a single quote before the path, a single quote at the end of the path, and a single quote and an exclamation point before OpenForm.
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2018
              Experts Exchange Top Expert VBA 2018
              Experts Exchange Distinguished Expert in Excel 2018
Avatar of Noah

ASKER

Okay I have noted all of your advice! Thanks again :)