Open 1 WorkBook with 2 WorkSheets from TextBoxes

Andresleo47

Board Regular
Joined
Oct 29, 2008
Messages
132
Hi Community! I am trying to open one Workbook with the 2 TimeSheets in the attached TextBoxes.

This is the code I have for now, but it's giving me an error:

Sub CommandButton1_Click()

Workbooks.Add.SaveAs Filename:="ThisWeek.xlsx"
ActiveWorkbook.Worksheets.Add Count:=1

With Sheets("Sheet1")
Workbooks.Open .TextBox1.Text
End With
With Sheets("Sheet2")
Workbooks.Open .TextBox2.Text
End With
End Sub


Any ideas would be appreciated!!
 

Attachments

  • Capture5.PNG
    Capture5.PNG
    22.4 KB · Views: 10

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Adding more details, I would like a New Excel file to be opened with 2 sheets (The 2 sheets should have the information coming from each TextBox), and I would like it to be saved in "MyDocuments".

Kindly advise.

Thanks,
 
Upvote 0
Your code is trying to read the information from the new workbook. Since there are no textboxes in the newly created workbook, that is why it is not working.

When you create a new workbook, that new workbook is the active workbook.
 
Upvote 0
Thanks Johnny, so when I hit the CommandButton, an Excel file is created and saved as ThisWeek.xls, but nothing else happens and then is when I receive the error.

Any advise?

Regards,

Andres
 
Upvote 0
Thanks Johnny, so when I hit the CommandButton, an Excel file is created and saved as ThisWeek.xls, but nothing else happens and then is when I receive the error.

Any advise?
See my previous post for the reason why it is not working.
 
Upvote 0
Gotcha, thanks. Then this statement should be in the first modules?

xlWorkbook1 = xlApp.Workbooks.Open(TextBox1.Text)

How can I connect both workbooks (The one that I want to create and the one with the macro)?

Thanks so much for your help.

Regards,

Andres
 
Upvote 0
Your first 1st line of code creates/names/saves a workbook.
Your 2nd line of code adds a sheet to the new workbook.

What exactly are you wanting to do with this newly created and Active workbook?
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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