Hi,

This is my coding.........


Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim Wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim name As String

Set xlApp = New Excel.Application
Set Wb = xlApp.Workbooks.Open("E:\Projects\VB Excel to textfile\crse.xls")
Set ws = Wb.Sheets(1)
Open "C:\rolllist.xls" For Output As #1

For i = 1 To ws.UsedRange.Rows.Count
crseid = ws.Cells(i, 1)
crseno = ws.Cells(i, 2)
Print #1, crseid; crseno + "0"
Next i
Close #1


Wb.Close
Set Wb = Nothing
Set xlApp = Nothing
MsgBox "completed"
End Sub


crseid and crseno ---> output are getting displayed in the same row itself ( excel sheet that means A column) .But i dont need like this .I want to display crseid field in the column A and
crseno field in the B column .

Thanks in advance............

Print #1, crseid, crseno + "0"

Good Luck

Hi,
No, its not working.Still printing all the values in the same column A.

Don't know what to tell you. I tried this...

Dim FName As String, FNumb As Integer
FName = "c:\z\temp.txt"
FNumb = FreeFile
Open FName For Output As #FNumb
Print #FNumb, "test", "Test"
Close #FNumb

and got 10 spaces between each test. Then I tried this...

Dim FName As String, FNumb As Integer
FName = "c:\z\temp.txt"
FNumb = FreeFile
Open FName For Output As #FNumb
Print #FNumb, "test", FNumb + 0
Close #FNumb

and got eleven spaces between test and 1

Now, if you are trying to add a zero to a string then you should use the ampersand character (&) and not the addition character (+) or if you are trying to add a zero to a number then you should str(numbervariable) & "0".


Good Luck

Oh!!!....

I think I know what you are trying to say now....

You are trying to create a CSV file for excel to open aren't you???

Okay, then...

Print #1, crseid & "," & crseno + "0"

Good Luck

I have the same question as the initial poster, and your response isn't what I, at least, want to do. I have a function and I want it to output one word in the current cell and one in the cell to the right (i.e., the next column). Is there a way to write this in VB?

So, something along these lines (though this doesn't work):

Function test(word1 As String, word2 As String)
   test = word1
   test.Offset(0, 1) = word2
End Function

To create a *.CSV (Comma Seperated Values) file...

Print "some value,somevalue,somevalue,somevalue"
Print SomeVariable & "," & SomeOtherVariable & "," & AnotherVariable

as for your .offset that is .net code and this is the classic forum. Next time, copy the url if you need to and please post in the correct forum without resurrecting the dead.

Good Luck

You keep suggesting a .csv file .... but I don't want to create a file. I want to call a function and have it output a value in a cell other than the one I called the function from.
The offset code was just a guess for how I might accomplish this. I wasn't trying to post in the wrong forum; this seemed to be the right place.
But I've started a new thread here: http://www.daniweb.com/forums/post1007073.html#post1007073 if you might have any further suggestions.

This article has been dead for over six months. Start a new discussion instead.