Form doesn't activate workbook after Unload Me

wist

Board Regular
Joined
Nov 8, 2012
Messages
79
Hello experts,

not sure why this doesn't work but I want to activate a Worbook that I opened via form after the form closes but it doesn't do anything.

My Code

Code:
Private Sub OpenButton_Click()


Dim CName As String

If Country.Value = "Abu Dhabi" Then CName = "C:\IC\Intercompany Recs Middle East.xlsb"

On Error GoTo Konec
        If ReadOnly.Value = True Then Workbooks.Open filename:=CName, UpdateLinks:=False, ReadOnly:=True Else Workbooks.Open filename:=CName, UpdateLinks:=False
        CName = ActiveWorkbook.Name
                       
Konec:
    Unload Me
    Workbooks(CName).Activate
    MsgBox CName


            
End Sub

What's weird that Workbooks(CName).Activate doesn't work but MsgBox CName does display the Name of the Woorkbook.

Thank youu
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Not sure if these will help but: swap the Unload Me and Workbooks(CName).Activate round. If that doesn't work, try an additional Workbooks(CName).Select before the Unload.
Regards
John
 
Upvote 0
Does using Set help:

Code:
Set CName = ActiveWorkbook.Name
 
Upvote 0
Thanks Fluff. I did actually read that sometime in the past now you mention it. I'm old and I forgot. That's my excuse.
 
Upvote 0
Thanks for the suggestions. It turns out that it was this line of code doing the damage. Once I removed it worked even without having to activate anything.

Code:
Private Sub UserForm_Initialize()

Me.MultiPage1.Value = 0

...

End Sub

I wanted to have the first Tab active once I load the form and I achieved it by only having this tab active in the VBA editor.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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
Back
Top