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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to the second worksheet in Excel

Status
Not open for further replies.

hexOffender

Programmer
Nov 6, 2006
146
US
I have an Excel Workbook that gets printed with client name, dob, etc. I just added a second worksheet to the workbook, but how do I write to cells on the second worksheet.

Dim xlApp As New Excel.Application
Dim xlWB As Excel.Workbook = Nothing
Dim Path As String = "Q:\eFormsPrinter\Clinic Encounter Form.xls"
xlWB = xlApp.Workbooks.Open(Path, , )

' Set the value of the Cell


xlApp.Cells(1, 20).value = mstrPatientName
xlApp.Cells(2, 20).value = mstrDOB
xlApp.Cells(3, 20).value = mstrAcct
xlApp.Cells(4, 20).value = mstrMr
xlApp.Cells(5, 20).value = mstrService
xlApp.Cells(6, 20).value = mstrDte
xlApp.Worksheets.PrintOut()
xlWB.Close(False)
xlApp.Workbooks.Close()
xlApp.Quit()
 

hi,
Code:
'sheet2 using the Sheet Index Seq nbr
    [b]xlbw.Sheets(2)[/b].Cells(1, 20).Value = mstrPatientName
'or using the sheet "tab" name
    [b]xlbw.Sheets("Sheet2")[/b].Cells(1, 20).Value = mstrPatientName
'or using the sheet CodeName
    [b]xlbw.Sheet2[/b].Cells(1, 20).Value = mstrPatientName
'but don't use the application object alone!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top