Open Workbook and Activate Sheet1

mikec007

New Member
Joined
Dec 1, 2010
Messages
38
I have a userform that the user will input the file location of the excel file to open.

How do I open that file, and activate Sheet1 of that file. I will not know that exact name of the first sheet in the newly opened excel workbook so I have to use the Sheet1.

I have the code:

Application.Workbooks.Open xlxlocation.Text

Sheets(Sheet1).Activate

But it errors about because there are two Sheet1. (one from the excel file with the userform program and one from the newly opened excel file. How do it tell it to activate the sheet1 from the xlxlocation.text location.

xlxlocation.text = full file name (C:/ahldfl/asldjfd/workbook.xls)

I know it is something simple but I cannot figure it out. I think you may have to use "With" but i am just beginning.
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try

Code:
Workbooks.Open xlxlocation.Text
ActiveWorkbook.Sheet1.Activate
 
Upvote 0
Try

Code:
Workbooks.Open xlxlocation.Text
ActiveWorkbook.Sheet1.Activate

It keeps giving me an mismatch error. I tryed both your code and :

ActiveWorkbook.Sheets(Sheet1).Activate

Both error out. I have tried screenupateing true and false. Nothing works.

It is like it doesnt activate the the workbook when its opened.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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