Unable to activate a workbook

Wooders

New Member
Joined
Feb 9, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
I am trying to open and activate a workbook from an already open workbook. I select a workbook to open using the Open Dialogue box as I don't know the location of the target file plus the name of the file changes regularly.
Once selected and open, I am not able to activate it to work on it.

My MsgBox is for testing and it shows the correct name of the target file but the active workbook remains that of the original file containing my code.

My code is

Sub openUpdate()
Dim strFile As String
On Error Resume Next
strFile = Application.GetOpenFilename(FileFilter:="Excel files (*.xl*),*.xl*", Title:="Select the Daily Update File")
strFile = Split(strFile, "\")(UBound(Split(strFile, "\")))
Workbooks(strFile).Activate
MsgBox (strFile & " " & ActiveWorkbook.Name)
End Sub
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,091
Office Version
  1. 2013
Platform
  1. Windows
No need to activate the newly opened workbook, already activated
Any way
Use something like
VBA Code:
 Windows.Workbooks(strFile).Activate
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,549
Office Version
  1. 365
Platform
  1. Windows
The code you've posted isn't opening the other workbook, which is why you cannot activate it.
Is that all your code?
 
Solution

Wooders

New Member
Joined
Feb 9, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
The code you've posted isn't opening the other workbook, which is why you cannot activate it.
Is that all your code?
Well spotted Fluff. I just needed to add Workbooks.Open (strFile).
DOH! I was getting tied in a knot trying to get the filename in a format that Open could address and then left the command out.
Thank you.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,549
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,590
Messages
5,625,674
Members
416,125
Latest member
NeedExcelHelp2021

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