Thread: Worksheet name
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Worksheet name

Hi Anthony,

Try something like:

'=============
Private Sub cmdUpdate_Click()
Dim fname As String, ws1 As String
Dim ws As Worksheet

fname = txtFileName.Text

Workbooks.Open fname
On Error Resume Next
Set ws = ActiveWorkbook.Sheets(txtWorksheet.Text)
If ws Is Nothing Then
MsgBox "Please input name of Worksheet"
End If
On Error GoTo 0

If Not ws Is Nothing Then
Call Module1.CopyPrice(ws, 4)
End If

End Sub
'<<=============


---
Regards,
Norman



"Anthony" wrote in message
...
Hi,
Hope someone can help.
I created a form and has a text box in it. User key in the name of the
worksheet in the text box but I stumble upon a compile error. My code is
as
below

Private Sub cmdUpdate_Click()
Dim fname, ws1 As String
Dim ws As Worksheet
fname = txtFileName

Workbooks.Open fname
Set ws = txtWorksheet
If ws = "" Then
MsgBox "Please input name of Worksheet"
End If
Call Module1.CopyPrice(ws, 4)

End Sub