Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-27-2008, 03:08 PM
teepee
 
Posts: n/a
Saving as CSV

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


Reply With Quote
  #2 (permalink)  
Old 04-27-2008, 04:31 PM
Bob Phillips
 
Posts: n/a
Re: Saving as CSV

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


--
HTH

Bob

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

"teepee" <nomail@nomail.com> wrote in message
news:481488cc$1@newsgate.x-privat.org...
>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
>



Reply With Quote
  #3 (permalink)  
Old 04-27-2008, 05:12 PM
teepee
 
Posts: n/a
Re: Saving as CSV


"Bob Phillips" <bob.ngs@somewhere.com> wrote in message
news:%23cm30uHqIHA.552@TK2MSFTNGP06.phx.gbl...
> 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


Reply With Quote
  #4 (permalink)  
Old 04-27-2008, 05:36 PM
teepee
 
Posts: n/a
Re: Saving as CSV


"Bob Phillips" <bob.ngs@somewhere.com> wrote in message
news:%23cm30uHqIHA.552@TK2MSFTNGP06.phx.gbl...
> 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-)


Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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



All times are GMT. The time now is 04:05 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Advertising | Loans | Destin, Florida | Mortgage | Current Accounts



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114