How to Set WS = Sheet1 from unopened Workbook

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
My application C:\MyCompany\CheckForm.xls loads with:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Code:
[FONT=Verdana]Private Sub UserForm_Activate()<o:p></o:p>[/FONT]
[FONT=Verdana] Dim iRow As Long<o:p></o:p>[/FONT]
[FONT=Verdana] Dim WS As Worksheet<o:p></o:p>[/FONT]
[FONT=Verdana]Set WS = Worksheets("Sheet1")[/FONT]
<o:p></o:p>
I want to access the data in Sheet1 without opening the entire application with all its Vba code and reports and other UserForms.<o:p></o:p>
<o:p></o:p>
So, if I move the data to a different workbook C:\MyCompany\Data.xls (Sheet1), how do I change the code?

And, isn't it a good idea to keep the data in a separate file/location?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You need to add a workbook reference.

Code:
Private Sub UserForm_Activate()
 Dim iRow As Long
 Dim WB as Workbook
 Dim WS As Worksheet
Set WB = Workbooks.Open "C:\MyCompany\Data.xls"
Set WS = WB.Worksheets("Sheet1")

{your code}
WB.Close SaveChanges:=True|False 'when you're done
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,769
Members
452,941
Latest member
Greayliams

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