Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / April 2008

Tip: Looking for answers? Try searching our database.

Saving as CSV

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
teepee - 27 Apr 2008 15:08 GMT
I have the following macro to sort and date stamp my data and export it as
text. My query is how to export it as csv. Anyone have any suggestions?

Many thanks

TP

Dim campaign As String
campaign = Range("b3")

   Range("A1:DB524").Select
   Selection.Copy
   Sheets("export").Select
   Range("A1").Select
   Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
       :=False, Transpose:=False

   Range("A1:DB524").Select
   Cells.Replace What:="0", Replacement:="", LookAt:=xlPart, SearchOrder:=
_
       xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False
       Range("e3") = ""

   Dim r As Range, c As Range
   Dim sTemp As String

   Open "Booking " & campaign & " " & Format(Date, "dd-mm-yy") + "_" +
Format(Time, "hh-mm-ss") & ".txt" For Output As #1

   For Each r In Selection.Rows
       sTemp = ""
       For Each c In r.Cells
           sTemp = sTemp & c.Text & Chr(9)
       Next c

       'Get rid of trailing tabs
       While Right(sTemp, 1) = Chr(9)
           sTemp = Left(sTemp, Len(sTemp) - 1)
       Wend
       Print #1, sTemp
   Next r
   Close #1

   Range("A1:DB524").Select
   Application.CutCopyMode = False
   Selection.ClearContents
   Range("A1").Select
   Sheets("Main").Select
   Range("A1").Select

End Sub
Bob Phillips - 27 Apr 2008 16:31 GMT
Instead of opening a text file and outputting one line at a time, save it as
CSV

   ActiveWorkbook.SaveAs Filename:="C:\myDir\myFile", FileFormat:=xlCSV

Signature

HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

>I have the following macro to sort and date stamp my data and export it as
>text. My query is how to export it as csv. Anyone have any suggestions?
[quoted text clipped - 49 lines]
>
> End Sub
teepee - 27 Apr 2008 17:12 GMT
> Instead of opening a text file and outputting one line at a time, save it
> as CSV
>
>    ActiveWorkbook.SaveAs Filename:="C:\myDir\myFile", FileFormat:=xlCSV

Yes but then it wouldn't be time stamped and I couldn't carry on working in
the original file
teepee - 27 Apr 2008 17:36 GMT
> Instead of opening a text file and outputting one line at a time, save it
> as CSV
>
>    ActiveWorkbook.SaveAs Filename:="C:\myDir\myFile", FileFormat:=xlCSV

Sorry I'm talking rubbish. Yes that's much better. Thanks for the reality
check 8-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.