Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to? Display xls cell value in a userform or message box 1

Status
Not open for further replies.

Firery

Technical User
Sep 23, 2003
18
AU
I wish to display a message box or userform, which will display the value of certain cells from a workbook.

eg. Sheet 1, Range a1 = "12th Dec 2003"

I want the userform to display "12th Dec 2003"

I know that this is probably a menial task for most of you but I would appreciate the help anyway.

Thanks
Firery
 
Remember to add the reference to the excel object library and...
Code:
Option Explicit

Private Sub Command1_Click()
Dim xlApp As New Excel.Application
Dim xlWb As Excel.Workbook
Dim xlSh As Excel.Worksheet

' Open excel file and set the sheet name
Set xlWb = xlApp.Workbooks.Open("c:\book1.xls")
Set xlSh = xlWb.Worksheets("Sheet1")

' return value of cell A1
MsgBox xlSh.Range("A1")

' Clean Up
xlWb.Close
xlApp.Quit
Set xlSh = Nothing
Set xlWb = Nothing
Set xlApp = Nothing

End Sub

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Thanks ca8msm

Actually, all I needed was

Private Sub CommandButton1_Click()

' return value of cell A1
MsgBox Range("A1")

End Sub


Took me a little while to figure it out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top