Enter value in textbox userform from a closed sheet on my pc

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,806
Office Version
  1. 2007
Platform
  1. Windows
Hi.
I have a userform with various textboxes.
I wish to populate each of these textboxes from sheets that are closed & on my pc.

Please advise how i write this correctly so the value is shown in the textbox in question.

TextBox1 should show the value from this files path

C:\Users\Ian\Desktop\EBAY\ACCOUNTS\PREVIOUS ACCOUNTS\2010 - 2011

Excel sheet is called SUMMARY 2010 - 2011.xlsl

The value is in cell E63


Once advise i can the follow / edit it for the other TextBoxes
Many Thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this: I assume that Cell E63 is on First Sheet in file.
Add this Function to a module

VBA Code:
Option Explicit

Public Function GetTextBoxValue() As String
Dim xlApp As Excel.Application, wb As Workbook, sht As Worksheet
Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open("C:\Users\Ian\Desktop\EBAY\ACCOUNTS\PREVIOUS ACCOUNTS\2010 - 2011\SUMMARY 2010 - 2011.xlsx")
Set sht = wb.Sheets(1)
GetTextBoxValue = sht.Range("E63").Value
wb.Close
xlApp.Quit
End Function

And use like following:

VBA Code:
Me.TextBox1.Text = GetTextBoxValue
 
Upvote 0
There is only the one sheet.
What do i call the module or how does it know what to look for.
 
Upvote 0
Dont think that will work as the sheets in question will be more that 1 with different folders.
 
Upvote 0
It's a Function. You can place it anywhere. I would put it in Form code module. Or, insert a new Module and place it there. Call with
VBA Code:
Module1.GetTextBoxValue
 
Upvote 0
That would be for one specific TextBox. It could be modified so that you could enter a Workbook name to retrieve the Value. Or, if the Values are in the same Workbook then you could add a Range argument.
 
Upvote 0
Sure. But first explain a little more. Let's say you have multiple TextBoxes. Are the values for ALL of them stored in the same Workbook but in different Cells? Will this code ever be used to retrieve values from a different Workbook?
 
Upvote 0
I will get the figures & put on sheet where the code for that Textbox will then lok in a cell.
Something like this but one that works, ha ha
I will then copy the code for each & edit the T1 to the correct cell

VBA Code:
Private Sub TextBox1_Change()
TextBox1.Value = Range("T1").TextBox1.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

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