Workbook Activate Issue

AndrewGKenneth

Board Regular
Joined
Aug 6, 2018
Messages
59
Dear all,

Thanks in advance for your help. I am having a slight issue with my code below. What I am hoping to achieve with this code is that the user enters their details into a userform (Employee Number and Password) and then they are taken to their own workbook and the current workbook is closed. This is working fine, apart from when the user has another document open on their computer. The problem I am having is that the file (in this case "10018 - Assembly") is not showing as the activeworkbook if the user has another file open on their computer. Instead, whatever file they may have open is showing as the activeworkbook despite my code. . I really need the (10018 - Assembly) file to be activated. Any suggestions on how to fix this?

Application.ScreenUpdating = True

If TextBox_EmployeeNumber.Value = "10018" And Textbox_Password.Value = "190453" Then

Workbooks.Open Filename:="X:\Drawing - Pricing\Absence Data\10018 - Assembly.xlsm"

Workbooks("10018 - Assembly.xlsm").Activate

ThisWorkbook.Close SaveChanges:=True

Unload Me

End If

Application.ScreenUpdating = False

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Andrew,

This link shows a method: https://social.msdn.microsoft.com/Forums/vActivate-an-already-open-excel-workbook?forum=vsto

Here is the VBA you might try: an example to check if the workbook is open or not. If not open it open the workbook:
VBA Code:
Sub CheckIfOpen()

Dim wbName As String = "Test.xlsx"
Dim PathName As String = "c:\Test\" & wbName
Dim wbBook As Excel.Workbook

For Each wbBook In xlApp.Workbooks
If wbBook.Name = wbName Then
wbBook.Activate()

Exit Sub
End If

Next

Dim xl_wbBook As Excel.Workbook = xlApp.Workbooks.Open(PathName) 

End Sub
 
Upvote 0
Hi again Doug,

I think this is the right solution to my problem, but cannot seem to apply it to my code (as still a beginner in VBA). Would you be able to help me with this? I am struggling to get it to work. I think it may be something to do with the xlapp.workbooks element. Thank you !
 
Upvote 0
Hi again Doug,

I think this is the right solution to my problem, but cannot seem to apply it to my code (as still a beginner in VBA). Would you be able to help me with this? I am struggling to get it to work. I think it may be something to do with the xlapp.workbooks element. Thank you !

Hi Andrew,

If you post your code along with any particular information on tables you think will explain the situation, then we'll all be able to see what might be going on.
Also, what excel version do you have?
Are your excel programs running on a virtual network e.g., Citrix network or any other form of virtual server?

Kind regards,

Doug
 
Upvote 0
Hi Doug,

Sorry for the late reply, I wasn't in the office over the weekend but have managed to resolve the issue this morning :). Thanks again for all your help much appreciated!
 
Upvote 0

Forum statistics

Threads
1,215,654
Messages
6,126,048
Members
449,282
Latest member
Glatortue

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