PDA

View Full Version : VBA uploading spreadsheets



broncorider
03-14-2007, 11:24 PM
Ok here is my problem.

I have made a user form the loads everytime I load the spreadsheet. That user form has 4 selections. Each selection takes the user form to a different spreadsheet. These other spreadsheets are located on my harddrive that VBA opens up. This is the code I have in my VBA.


Private Sub CommandButton1_Click()
Workbooks.Open Filename:= _
"C:\VBA CLASS\stockoptions.xls"
UserForm1.Hide
End Sub
Private Sub CommandButton2_Click()
Workbooks.Open Filename:= _
"C:\VBA CLASS\Stocktrading.xls"
UserForm1.Hide
End Sub
Private Sub CommandButton3_Click()
Workbooks.Open Filename:= _
"C:\VBA CLASS\Options_Model.xls"
UserForm1.Hide
End Sub
Private Sub CommandButton4_Click()
Workbooks.Open Filename:= _
"C:\VBA CLASS\StockQuery_Allen.xls"
UserForm1.Hide
End Sub

My question is if I copy these 4 spreadsheets into the orginal spreadsheet as new tabs, what code do I write to pull each of the spreadsheets up without having to go to my C: drive to pull them up?
These 4 spreadsheets that are seperated in the user form that I created are now in my orginal spreadsheet where the user form pops up.

Aussiebear
03-15-2007, 12:44 AM
If these are now going to be sheets within the same workbook, why would you need the form? Why not simply select the sheet tab required?

broncorider
03-15-2007, 01:03 AM
because I need the user form to pull the spreadsheets up...

moa
03-15-2007, 03:20 AM
Assuming you name your sheets the same as the file names:

Private Sub CommandButton1_Click()
ThisWorkbook.Sheets("stockoptions").Activate
Unload Me
End Sub

Private Sub CommandButton2_Click()
ThisWorkbook.Sheets("Stocktrading").Activate
Unload Me
End Sub

Private Sub CommandButton3_Click()
ThisWorkbook.Sheets("Options_Model").Activate
Unload Me
End Sub

Private Sub CommandButton4_Click()
ThisWorkbook.Sheets("StockQuery_Allen").Activate
Unload Me
End Sub