Click here to Skip to main content
16,005,141 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: search files on hard drive by vb 6.0 Pin
Eddy Vluggen7-May-10 0:39
professionalEddy Vluggen7-May-10 0:39 
AnswerRe: search files on hard drive by vb 6.0 Pin
Chris Quinn12-May-10 5:25
Chris Quinn12-May-10 5:25 
QuestionLinkLabel redirect Pin
Syasyaaa6-May-10 20:56
Syasyaaa6-May-10 20:56 
AnswerRe: LinkLabel redirect Pin
εїзεїзεїз6-May-10 22:13
εїзεїзεїз6-May-10 22:13 
Questionto transfer data to each sheet of a excel workbook [modified] Pin
sanyexian6-May-10 18:38
sanyexian6-May-10 18:38 
AnswerRe: to transfer data to each sheet of a excel workbook Pin
Johan Hakkesteegt6-May-10 20:20
Johan Hakkesteegt6-May-10 20:20 
GeneralRe: to transfer data to each sheet of a excel workbook [modified] Pin
sanyexian8-May-10 15:26
sanyexian8-May-10 15:26 
AnswerRe: to transfer data to each sheet of a excel workbook Pin
Sonhospa6-May-10 23:06
Sonhospa6-May-10 23:06 
Hi sanyexian,

I changed your code a little bit so that it works. Still you might encounter many traps, since communication with Excel (i.e. COM / Office) can be very tricky sometimes. Also don't forget the small things, like making your assembly COM visible (project properties). You'll find tons of material about the issue here and in the web - and a lot is worth reading. Good luck Wink | ;)
Sub OperateExcel()
    ' Compile with Option Strict Off to allow late binding.
    Dim xlsApp As Object
    Dim xlsBook As Object
    Dim xlsSheet As Object

    xlsApp = CreateObject("Excel.Application")
    ' Late bind an instance of an Excel workbook.
    xlsBook = xlsApp.Workbooks.Add
    ' Late bind an instance of an Excel worksheet.
    xlsSheet = xlsBook.Worksheets(1)
    xlsSheet.Activate()
    ' Show the application.
    xlsSheet.Application.Visible = True

    For Each xlsSheet In xlsBook.worksheets
        ' put your text into the cells in a simpler way
        xlsSheet.Range("H3").Value = "txtProduct"
        xlsSheet.Range("H4").Value = "txtName"
        xlsSheet.Range("H5").Value = "txtNum"
        ' A more useful way since you can iterate through rows/colums
        ' Here: Place some text in the second row of the sheet.
        xlsSheet.Cells(2, 8) = "This is column H row 2"
    Next
    xlsBook.SaveAs("D:\text.xls")
    xlsBook.Close()
    xlsApp.Quit()

    xlsSheet = Nothing
    xlsBook = Nothing
    xlsApp = Nothing
End Sub

GeneralRe: to transfer data to each sheet of a excel workbook Pin
Johan Hakkesteegt6-May-10 23:30
Johan Hakkesteegt6-May-10 23:30 
GeneralRe: to transfer data to each sheet of a excel workbook Pin
Sonhospa7-May-10 4:56
Sonhospa7-May-10 4:56 
GeneralRe: to transfer data to each sheet of a excel workbook [modified] Pin
sanyexian8-May-10 15:17
sanyexian8-May-10 15:17 
AnswerRe: to transfer data to each sheet of a excel workbook Pin
Sonhospa10-May-10 22:47
Sonhospa10-May-10 22:47 
QuestionRunning New Processes on a Remote Computer with Output Pin
Stinebaugh6-May-10 16:25
Stinebaugh6-May-10 16:25 
AnswerRe: Running New Processes on a Remote Computer with Output Pin
Johan Hakkesteegt6-May-10 20:31
Johan Hakkesteegt6-May-10 20:31 
GeneralRe: Running New Processes on a Remote Computer with Output Pin
Stinebaugh7-May-10 6:37
Stinebaugh7-May-10 6:37 
GeneralRe: Running New Processes on a Remote Computer with Output Pin
Johan Hakkesteegt9-May-10 21:55
Johan Hakkesteegt9-May-10 21:55 
Questiongetting complete name of account NT server Pin
sal216-May-10 10:00
sal216-May-10 10:00 
AnswerRe: getting complete name of account NT server Pin
Stinebaugh6-May-10 16:30
Stinebaugh6-May-10 16:30 
GeneralRe: getting complete name of account NT server Pin
sal216-May-10 20:33
sal216-May-10 20:33 
GeneralRe: getting complete name of account NT server Pin
Stinebaugh7-May-10 6:22
Stinebaugh7-May-10 6:22 
GeneralRe: getting complete name of account NT server Pin
sal217-May-10 11:56
sal217-May-10 11:56 
QuestionMultithreading slower? [modified] Pin
NikWing6-May-10 5:36
NikWing6-May-10 5:36 
AnswerRe: Multithreading slower? Pin
Luc Pattyn6-May-10 5:52
sitebuilderLuc Pattyn6-May-10 5:52 
GeneralRe: Multithreading slower? Pin
NikWing6-May-10 6:33
NikWing6-May-10 6:33 
GeneralRe: Multithreading slower? Pin
Luc Pattyn6-May-10 7:00
sitebuilderLuc Pattyn6-May-10 7:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.