Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How can I...

Ok, I have a Visual Basic program that I would like to use to send
information into a worksheet designated as a Common Seperator Value file. So,
in my program I have set a single variable to contain all information for one
line seperated by commas (,) to distinguish which part of the line goes into
which column. Now, as it stands this works beautifully with one MAJOR
exception- Every time I send the 'line' to the CSV file, it simply overwrites
the previous data. What I want to happen is when I send the info to excel it
follows these steps (or at least to this effect):

1. Open the CSV file
2. Write Ln
3. Drop the cursor to the next row
4. Save and close the file

Can anyone help with this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I...

Something like this should work (substitute the sample filename and output
line with your actual items...

Dim FF As Long
......
......
FF = FreeFile
Open "c:\Your\Path\And\Filename.csv" For Append As #FF
Print #FF, YourLineOfCommaSeparatedText
Close #FF

Rick


"markythesk8erboi" wrote in
message ...
Ok, I have a Visual Basic program that I would like to use to send
information into a worksheet designated as a Common Seperator Value file.
So,
in my program I have set a single variable to contain all information for
one
line seperated by commas (,) to distinguish which part of the line goes
into
which column. Now, as it stands this works beautifully with one MAJOR
exception- Every time I send the 'line' to the CSV file, it simply
overwrites
the previous data. What I want to happen is when I send the info to excel
it
follows these steps (or at least to this effect):

1. Open the CSV file
2. Write Ln
3. Drop the cursor to the next row
4. Save and close the file

Can anyone help with this?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How can I...

Ok, um...... This is the code I have so I'm gonna need help changing it.

'Writing the stuff to a file
'1)setting variables


If Option1 = True Then BEAVIS = "Silex,186Y9Y"
If Option2 = True Then BEAVIS = "Customer," + Text25.Text
'end of setting "bill to" option variables

REDDYFILE = "C:\Documents and Settings\Silex Dock\Desktop\Shipment History
CSVFILE.csv"
Err.Clear

Set XYZZYX = CreateObject("Scripting.filesystemobject")
Set ABACABB = XYZZYX.createTextfile(REDDYFILE, True)

ALLINFOV = Text2.Text + "," + Text3.Text + "," + Text4.Text + "," +
Combo1.Text + "," + Text6.Text + "," + Text7.Text + "," + BEAVIS + "," +
Text8.Text + "," + Text5.Text + "," + Text26.Text + "," + Text1.Text + "," +
Text27.Text + "," + Text28.Text + "," + Text29.Text + "," + Text30.Text + ","
+ Text32.Text
'now ALLINFOV is a variable that is equal to the entire line of info I want
to write to file
Text31.Text = ALLINFOV 'now text31 is the line of ALLINFOV
MsgBox ("is everything ok") 'Pause before submittal

ABACABB.writeline (ALLINFOV) 'write ln
ABACABB.Close 'close file



Please keep in mind this is inside the sub routine of a command button and
if I need to create anything in the general scripting I need to know that.
I'm a noobie... sorry




"Rick Rothstein (MVP - VB)" wrote:

Something like this should work (substitute the sample filename and output
line with your actual items...

Dim FF As Long
......
......
FF = FreeFile
Open "c:\Your\Path\And\Filename.csv" For Append As #FF
Print #FF, YourLineOfCommaSeparatedText
Close #FF

Rick


"markythesk8erboi" wrote in
message ...
Ok, I have a Visual Basic program that I would like to use to send
information into a worksheet designated as a Common Seperator Value file.
So,
in my program I have set a single variable to contain all information for
one
line seperated by commas (,) to distinguish which part of the line goes
into
which column. Now, as it stands this works beautifully with one MAJOR
exception- Every time I send the 'line' to the CSV file, it simply
overwrites
the previous data. What I want to happen is when I send the info to excel
it
follows these steps (or at least to this effect):

1. Open the CSV file
2. Write Ln
3. Drop the cursor to the next row
4. Save and close the file

Can anyone help with this?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I...

Replace all the code you posted with this...

If Option1 = True Then BEAVIS = "Silex,186Y9Y"
If Option2 = True Then BEAVIS = "Customer," + Text25.Text
Err.Clear ' I wasn't sure about this line, but left it in because you had
it
REDDYFILE = "C:\Documents and Settings\Silex Dock\" & _
"Desktop\Shipment History CSVFILE.csv "
ALLINFOV = Text2.Text & "," & Text3.Text & "," & Text4.Text & _
"," & Combo1.Text & "," & Text6.Text & "," & Text7.Text & _
"," & BEAVIS & "," & Text8.Text & "," & Text5.Text & _
"," & Text26.Text & "," & Text1.Text & "," & Text27.Text & _
"," & Text28.Text & "," & Text29.Text & "," & Text30.Text & _
"," & Text32.Text
Text31.Text = ALLINFOV
Answer = MsgBox("Is everything OK?", vbQuestion Or vbYesNo, "Verifying")
If Answer = vbYes Then
FF = FreeFile
Open "c:\Your\Path\And\Filename.csv" For Append As #FF
Print #FF, "Your Line of comma separated text"
Close #FF
End If

And add this declaration to the section where you declared your other
variables...

Dim FF As Long
Dim Answer As Long

Note that I neatened up the long lines using line continuations so they
won't split apart awkwardly in your newsreader. I also added some structure
around the MsgBox to accept an answer to your question and then properly
handle it.

Rick


"markythesk8erboi" wrote in
message ...
Ok, um...... This is the code I have so I'm gonna need help changing it.

'Writing the stuff to a file
'1)setting variables


If Option1 = True Then BEAVIS = "Silex,186Y9Y"
If Option2 = True Then BEAVIS = "Customer," + Text25.Text
'end of setting "bill to" option variables

REDDYFILE = "C:\Documents and Settings\Silex Dock\Desktop\Shipment History
CSVFILE.csv"
Err.Clear

Set XYZZYX = CreateObject("Scripting.filesystemobject")
Set ABACABB = XYZZYX.createTextfile(REDDYFILE, True)

ALLINFOV = Text2.Text + "," + Text3.Text + "," + Text4.Text + "," +
Combo1.Text + "," + Text6.Text + "," + Text7.Text + "," + BEAVIS + "," +
Text8.Text + "," + Text5.Text + "," + Text26.Text + "," + Text1.Text + ","
+
Text27.Text + "," + Text28.Text + "," + Text29.Text + "," + Text30.Text +
","
+ Text32.Text
'now ALLINFOV is a variable that is equal to the entire line of info I
want
to write to file
Text31.Text = ALLINFOV 'now text31 is the line of ALLINFOV
MsgBox ("is everything ok") 'Pause before submittal

ABACABB.writeline (ALLINFOV) 'write ln
ABACABB.Close 'close file



Please keep in mind this is inside the sub routine of a command button and
if I need to create anything in the general scripting I need to know that.
I'm a noobie... sorry




"Rick Rothstein (MVP - VB)" wrote:

Something like this should work (substitute the sample filename and
output
line with your actual items...

Dim FF As Long
......
......
FF = FreeFile
Open "c:\Your\Path\And\Filename.csv" For Append As #FF
Print #FF, YourLineOfCommaSeparatedText
Close #FF

Rick


"markythesk8erboi" wrote in
message ...
Ok, I have a Visual Basic program that I would like to use to send
information into a worksheet designated as a Common Seperator Value
file.
So,
in my program I have set a single variable to contain all information
for
one
line seperated by commas (,) to distinguish which part of the line goes
into
which column. Now, as it stands this works beautifully with one MAJOR
exception- Every time I send the 'line' to the CSV file, it simply
overwrites
the previous data. What I want to happen is when I send the info to
excel
it
follows these steps (or at least to this effect):

1. Open the CSV file
2. Write Ln
3. Drop the cursor to the next row
4. Save and close the file

Can anyone help with this?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How can I...

OMFG!!! THANK YOU!!! Please note (for other potential viewers) that I had to
delete the reoccuring = ALLINFOV at the end of the line that begins with
ALLINFOV=

and I had to omit all underscoring. And of corse replace the C: my file
references but other then that it works BEAUTIFULLY!!!!!!!!!!

One last thing rick..... I would like to delete all information in the
spreadsheet that is there now and start completely over. But when I go to
save it an error message occurs and says something to the effect of " file
may contain features that are not compatible with CSV. Do you want to keep
the workbook in this format?"

I think its trying to tell me that I'm trying to save a .csv file as a
normal excel worksheet?


"Rick Rothstein (MVP - VB)" wrote:

Replace all the code you posted with this...

If Option1 = True Then BEAVIS = "Silex,186Y9Y"
If Option2 = True Then BEAVIS = "Customer," + Text25.Text
Err.Clear ' I wasn't sure about this line, but left it in because you had
it
REDDYFILE = "C:\Documents and Settings\Silex Dock\" & _
"Desktop\Shipment History CSVFILE.csv "
ALLINFOV = Text2.Text & "," & Text3.Text & "," & Text4.Text & _
"," & Combo1.Text & "," & Text6.Text & "," & Text7.Text & _
"," & BEAVIS & "," & Text8.Text & "," & Text5.Text & _
"," & Text26.Text & "," & Text1.Text & "," & Text27.Text & _
"," & Text28.Text & "," & Text29.Text & "," & Text30.Text & _
"," & Text32.Text
Text31.Text = ALLINFOV
Answer = MsgBox("Is everything OK?", vbQuestion Or vbYesNo, "Verifying")
If Answer = vbYes Then
FF = FreeFile
Open "c:\Your\Path\And\Filename.csv" For Append As #FF
Print #FF, "Your Line of comma separated text"
Close #FF
End If

And add this declaration to the section where you declared your other
variables...

Dim FF As Long
Dim Answer As Long

Note that I neatened up the long lines using line continuations so they
won't split apart awkwardly in your newsreader. I also added some structure
around the MsgBox to accept an answer to your question and then properly
handle it.

Rick


"markythesk8erboi" wrote in
message ...
Ok, um...... This is the code I have so I'm gonna need help changing it.

'Writing the stuff to a file
'1)setting variables


If Option1 = True Then BEAVIS = "Silex,186Y9Y"
If Option2 = True Then BEAVIS = "Customer," + Text25.Text
'end of setting "bill to" option variables

REDDYFILE = "C:\Documents and Settings\Silex Dock\Desktop\Shipment History
CSVFILE.csv"
Err.Clear

Set XYZZYX = CreateObject("Scripting.filesystemobject")
Set ABACABB = XYZZYX.createTextfile(REDDYFILE, True)

ALLINFOV = Text2.Text + "," + Text3.Text + "," + Text4.Text + "," +
Combo1.Text + "," + Text6.Text + "," + Text7.Text + "," + BEAVIS + "," +
Text8.Text + "," + Text5.Text + "," + Text26.Text + "," + Text1.Text + ","
+
Text27.Text + "," + Text28.Text + "," + Text29.Text + "," + Text30.Text +
","
+ Text32.Text
'now ALLINFOV is a variable that is equal to the entire line of info I
want
to write to file
Text31.Text = ALLINFOV 'now text31 is the line of ALLINFOV
MsgBox ("is everything ok") 'Pause before submittal

ABACABB.writeline (ALLINFOV) 'write ln
ABACABB.Close 'close file



Please keep in mind this is inside the sub routine of a command button and
if I need to create anything in the general scripting I need to know that.
I'm a noobie... sorry




"Rick Rothstein (MVP - VB)" wrote:

Something like this should work (substitute the sample filename and
output
line with your actual items...

Dim FF As Long
......
......
FF = FreeFile
Open "c:\Your\Path\And\Filename.csv" For Append As #FF
Print #FF, YourLineOfCommaSeparatedText
Close #FF

Rick


"markythesk8erboi" wrote in
message ...
Ok, I have a Visual Basic program that I would like to use to send
information into a worksheet designated as a Common Seperator Value
file.
So,
in my program I have set a single variable to contain all information
for
one
line seperated by commas (,) to distinguish which part of the line goes
into
which column. Now, as it stands this works beautifully with one MAJOR
exception- Every time I send the 'line' to the CSV file, it simply
overwrites
the previous data. What I want to happen is when I send the info to
excel
it
follows these steps (or at least to this effect):

1. Open the CSV file
2. Write Ln
3. Drop the cursor to the next row
4. Save and close the file

Can anyone help with this?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I...

See inline comments...

OMFG!!! THANK YOU!!!


You are quite welcome.


Please note (for other potential viewers) that I had to delete the
reoccuring = ALLINFOV at the end of the line that begins with
ALLINFOV=


??? If I understand you correctly, you are talking about this line, right?

Text31.Text = ALLINFOV

That was your line to display the result of the concatenation so the user
could verify it. You originally had this comment above it...

now ALLINFOV is a variable that is equal to the entire
line of info I want to write to file

and this comment next to it....

now text31 is the line of ALLINFOV

so I am not sure why you are deleting it.


and I had to omit all underscoring. And of corse replace the C: my file
references but other then that it works BEAUTIFULLY!!!!!!!!!!


Actually, you didn't have to do that... the long lines I posted that had
them would have worked fine had you just copy/pasted them into your code
window. A <space character followed by an underscore **at the end of a
line** is called a "line continuation sequence"... VB knows to automatically
link the line with that to the next line following it and treat them as if
they were joined into a single line. The advantage of using line
continuation sequences is that your code becomes more readable (you don't
have to scroll way off to the right to see your whole line of code. The only
thing to watch out for is you cannot use them in the middle of a text
constant. So, this is **NOT** valid...

X = "Line One _
Line Two"

Rather, you have to split the text constant in two two sub-strings and use
the line continuation sequence with one of the ampersands
(concatenationation symbol), like this...

X = "Line One " & _
"Line Two"

By the way, I meant to mention in my last post... you should use the
ampersand (&) to concatenate text together rather than the plus sign (+)...
there are occasions when concatenating Variants that you can get results you
were not expecting.


One last thing rick..... I would like to delete all information in the
spreadsheet that is there now and start completely over. But when I go to
save it an error message occurs and says something to the effect of " file
may contain features that are not compatible with CSV. Do you want to keep
the workbook in this format?"

I think its trying to tell me that I'm trying to save a .csv file as a
normal excel worksheet?


I'm not sure what to tell you on this as I don't work with CSV files myself.
Hopefully someone with more experience with CSV files will come along and
help out.

Rick

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"