Results 1 to 2 of 2

Thread: Sequential excel outputs: How to write to a new column?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2014
    Posts
    17

    Sequential excel outputs: How to write to a new column?

    Hi everyone!

    I have looked up this problem in old threads and can't find an answer that I can get to work. This is the closest I've come: http://www.vbforums.com/showthread.p...cel+sequential

    I'm working on creating an excel output from a VB6 program.

    For the following code, I would like to specify the cell that the information in each line should be written to. Even better, I'd like to be able to put parts of each line in separate cells (e.g., the string "Subject age" in column 1 and the value "24" in column 2).

    Code:
     
    Private Sub Command1_Click()
    
    Open File_Name & ".xls" For Output As #1
    
    Write #1, "STAGE 1A"
    
    Write #1, "Subject name: " & Subject_Name
    Write #1, "The file name: " & File_Name
    Write #1,
    
    Write #1, "DEMOGRAPHICS"
    Write #1, "Subject age: " & age
    Write #1, "Subject gender: " & gender
    Write #1, "Subject ethnicity: " & ethnicity
    Write #1,
    Can anyone shed some light on how to do this? It must be simple, but I'm very inexperienced. I'd greatly appreciate any tips. "File_Name", "age" etc. are obviously variables defined elsewhere in the program. The above code works fine for creating an excel file as a list.

    Many thanks for taking the time!

  2. #2
    Addicted Member
    Join Date
    Jul 2014
    Posts
    176

    Re: Sequential excel outputs: How to write to a new column?

    Here's my sample code for creating an excel file from vb6... currently deployed in our system

    VB Code:
    1. Dim xl As New Excel.application
    2. Dim xlsheet As Excel.Worksheet
    3. Dim xlwbook As Excel.Workbook
    4.  
    5.  Set xl = CreateObject("Excel.Application")
    6.             Set xlwbook = xl.Workbooks.Add
    7.             Set xlsheet = xlwbook.Sheets(1)
    8.  
    9. xlsheet.Cells(1, 1) = "SAMPLE"
    10.  
    11. xl.Visible = True
    12. xlwbook.Close
    13. xl.Quit
    14.            
    15. Set xl = Nothing
    16. Set xlwbook = Nothing
    17. Set xlsheet = Nothing
    Last edited by terry002; Sep 10th, 2014 at 10:23 PM.
    If I had helped you...

    Don't forget to mark your Inquiry as RESOLVED...

    I will be glad if you can also give me some Reputation points in helping you (by Clicking Rate This Post)...

    Happy VB Coding Everyone!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width