timd
2004-09-16, 01:42 PM
I am trying to send information from CAD to Excel and am using the code below. My question is, how can I switch to a specific sheet name. I am having the user imput a sheet name in a CAD userform and I want the appropriate Excel sheet to be active. All the examples I can find have the transfer like this:
Set xlsheet = xlbook.Sheets("sheet1")
and I am wanting something more like
test = "A"
Set xlsheet = xlbook.Sheets(test)
but I can't seem to find the right line of code.
Private Sub CommandButton1_Click()
Dim xlapp As excel.Application
Dim xlbook As excel.workbook
Dim xlsheet As excel.worksheet
Set xlbook = GetObject("C:\Documents and Settings\TimD\Desktop\book1.xls")
'set reference to Excel file
Set xlapp = xlbook.Parent
'set reference to workbook
xlapp.Visible = True
'make Excel visible
xlapp.Windows("book1.XLS").Visible = True
'make the workbook visible
Set xlsheet = xlbook.Sheets("sheet1")
'set reference to the worksheet Sheet1
xlsheet.Cells(1, 1) = panel
xlsheet.Cells(1, 2) = circuit
xlsheet.Cells(1, 3) = description
xlsheet.Cells(1, 4) = load
Unload Me
End Sub
Set xlsheet = xlbook.Sheets("sheet1")
and I am wanting something more like
test = "A"
Set xlsheet = xlbook.Sheets(test)
but I can't seem to find the right line of code.
Private Sub CommandButton1_Click()
Dim xlapp As excel.Application
Dim xlbook As excel.workbook
Dim xlsheet As excel.worksheet
Set xlbook = GetObject("C:\Documents and Settings\TimD\Desktop\book1.xls")
'set reference to Excel file
Set xlapp = xlbook.Parent
'set reference to workbook
xlapp.Visible = True
'make Excel visible
xlapp.Windows("book1.XLS").Visible = True
'make the workbook visible
Set xlsheet = xlbook.Sheets("sheet1")
'set reference to the worksheet Sheet1
xlsheet.Cells(1, 1) = panel
xlsheet.Cells(1, 2) = circuit
xlsheet.Cells(1, 3) = description
xlsheet.Cells(1, 4) = load
Unload Me
End Sub