Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default Worksheet name

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default Worksheet name

Hi Norman,
Thanks. I tried but when I run to the below line, I get a "type mismatch"
error.
Set ws = ActiveWorkbook.Sheets(txtWorksheet.Text)

Could there be something wrong with the declaration I made?

Thanks & Regards
Anthony

"Norman Jones" wrote:

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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Worksheet name

Hi Anthony,

I assumed that txtWorksheet was a TextBox and,
in such case, using the suggested code, I was
unable to reproduce your error.

Could there be something wrong with the declaration I made?


Post the code which you used



---
Regards,
Norman

"Anthony" wrote in message
...
Hi Norman,
Thanks. I tried but when I run to the below line, I get a "type mismatch"
error.
Set ws = ActiveWorkbook.Sheets(txtWorksheet.Text)

Could there be something wrong with the declaration I made?

Thanks & Regards
Anthony

"Norman Jones" wrote:

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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default Worksheet name

Hi Norman

Below my code

Private Sub cmdBrowse_Click()

Dim fname, fn As String

fn = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select Panel Price file", , False)
txtFileName = fn 'Display to text box
Workbooks.Open fn

For Each sh In ActiveWorkbook.Sheets
Me.cbPriceWS.AddItem sh.Name
Next

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

Private Sub cmdBUCA_Click()

Dim fn As String
fn = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select BUCA file", , False)
txtBUCA = fn 'Display to textbox

End Sub

Private Sub cmdCancel_Click()

ActiveWorkbook.Close False

End Sub

Private Sub cbPriceWS_Change()

End Sub

Private Sub txtWorksheet_Change()

End Sub

Private Sub txtFilename_Change()

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

TemplateFile = ActiveWorkbook.FullName
i = 0
While InStr(i + 1, TemplateFile, Application.PathSeparator) 0
i = InStr(i + 1, TemplateFile, Application.PathSeparator)
Wend
txtTemplate = Right(TemplateFile, Len(TemplateFile) - i) 'wb1 = filename
of template

cbMonth.List = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
cbMonth.ListIndex = 0
'cbMonth.Locked = True
cbRegion.List = Array("Europe", "Nafta", "AP/China", "LATAM")
cbRegion.ListIndex = 0

txtFileName = ""
txtWorksheet = ""

End Sub


"Norman Jones" wrote:

Hi Anthony,

I assumed that txtWorksheet was a TextBox and,
in such case, using the suggested code, I was
unable to reproduce your error.

Could there be something wrong with the declaration I made?


Post the code which you used



---
Regards,
Norman

"Anthony" wrote in message
...
Hi Norman,
Thanks. I tried but when I run to the below line, I get a "type mismatch"
error.
Set ws = ActiveWorkbook.Sheets(txtWorksheet.Text)

Could there be something wrong with the declaration I made?

Thanks & Regards
Anthony

"Norman Jones" wrote:

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







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
automatically appending newly added data on worksheet to a master list worksheet tabylee via OfficeKB.com Links and Linking in Excel 0 December 17th 09 04:24 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Excel Worksheet Functions 2 September 7th 06 05:05 PM
plot graph from multiple worksheet as embedded chart object on every worksheet jeftiong New Users to Excel 0 August 23rd 06 01:50 PM
Upload multiple text files into 1 excel worksheet + put the filename as the first column in the worksheet Aster Excel Worksheet Functions 3 March 12th 06 09:58 AM
Attaching a JET database to an Excel Worksheet OR storing large binary data in a worksheet Ant Waters Excel Programming 1 September 3rd 03 11:34 AM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"