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
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
No need to activate the newly opened workbook, already activated
Any way
Use something like
VBA Code:
 Windows.Workbooks(strFile).Activate
 
Upvote 0
The code you've posted isn't opening the other workbook, which is why you cannot activate it.
Is that all your code?
 
Upvote 0
Solution
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.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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