Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Help saving file; exporting as .csv

Hello & help!!!
I'm all goofed up here, tried many things myself, and have failed miserably
(Excel 2000). Anyway, I need to export a range named EXPORTRANGE as .csv
format to C:\Lotus\Work\123, with the file name bake.csv. The range is
getting saved to the current directory (instead of C:\Lotus\Work\123), with
the name bakeadj.csv. I did see something about DIR returning the first found
file name in the directory, but couldn't figure out what to do about it;
bakeadj.csv is the first file. In addition to that, the exported range does
not put any commas in the file, just blank cells. Thanks for any help you
can give me. Totally messed up (and probably laughable) code follows:
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As String
Dim destpathname As String
Dim ColCount As Integer
Dim CurrCol As Integer
Dim filemask As String

destpathname = "C:\Lotus\Work\123\"
filemask = "bake.csv"
FName = Dir(destpathname & filemask, vbNormal)
ListSep = Application.International(xlListSeparator)

Range("EXPORTRANGE").Select
Set SrcRg = Selection
ColCount = SrcRg.Columns.Count
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrCol = 0
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrCol = CurrCol + 1
CurrTextStr = CurrTextStr & CurrCell.Value & IIf(CurrCol < _
ColCount, ListSep, "")

Next
Print #1, CurrTextStr
Next
Close #1

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Help saving file; exporting as .csv

Try this code. I didn't test the code, but it has only small number of
changes from your posted code. Dir function returns only the filename
without the path. i eliminated the DIR so the file gets saved in correct
directory.


Sub test()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As String
Dim destpathname As String
Dim ColCount As Integer
Dim CurrCol As Integer
Dim filemask As String

destpathname = "C:\Lotus\Work\123\"
filemask = "bake.csv"
FName = destpathname & filemask
ListSep = Application.International(xlListSeparator)

Range("EXPORTRANGE").Select
Set SrcRg = Selection
ColCount = SrcRg.Columns.Count
Open FName For Output As #1

For Each CurrRow In SrcRg.Rows
For Each CurrCell In CurrRow.Cells
If Len(CurrTextStr) = 0 Then
CurrTextStr = CurrCell.Value
Else
CurrTextStr = CurrTextStr & "," & _
CurrCell.Value
End If
Next CurrCell
Print #1, CurrTextStr
Next CurrRow
Close #1

End Sub


"cottage6" wrote:

Hello & help!!!
I'm all goofed up here, tried many things myself, and have failed miserably
(Excel 2000). Anyway, I need to export a range named EXPORTRANGE as .csv
format to C:\Lotus\Work\123, with the file name bake.csv. The range is
getting saved to the current directory (instead of C:\Lotus\Work\123), with
the name bakeadj.csv. I did see something about DIR returning the first found
file name in the directory, but couldn't figure out what to do about it;
bakeadj.csv is the first file. In addition to that, the exported range does
not put any commas in the file, just blank cells. Thanks for any help you
can give me. Totally messed up (and probably laughable) code follows:
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As String
Dim destpathname As String
Dim ColCount As Integer
Dim CurrCol As Integer
Dim filemask As String

destpathname = "C:\Lotus\Work\123\"
filemask = "bake.csv"
FName = Dir(destpathname & filemask, vbNormal)
ListSep = Application.International(xlListSeparator)

Range("EXPORTRANGE").Select
Set SrcRg = Selection
ColCount = SrcRg.Columns.Count
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrCol = 0
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrCol = CurrCol + 1
CurrTextStr = CurrTextStr & CurrCell.Value & IIf(CurrCol < _
ColCount, ListSep, "")

Next
Print #1, CurrTextStr
Next
Close #1

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Help saving file; exporting as .csv

Thanks Joel, the file is saving where it needs to go now.

"Joel" wrote:

Try this code. I didn't test the code, but it has only small number of
changes from your posted code. Dir function returns only the filename
without the path. i eliminated the DIR so the file gets saved in correct
directory.


Sub test()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As String
Dim destpathname As String
Dim ColCount As Integer
Dim CurrCol As Integer
Dim filemask As String

destpathname = "C:\Lotus\Work\123\"
filemask = "bake.csv"
FName = destpathname & filemask
ListSep = Application.International(xlListSeparator)

Range("EXPORTRANGE").Select
Set SrcRg = Selection
ColCount = SrcRg.Columns.Count
Open FName For Output As #1

For Each CurrRow In SrcRg.Rows
For Each CurrCell In CurrRow.Cells
If Len(CurrTextStr) = 0 Then
CurrTextStr = CurrCell.Value
Else
CurrTextStr = CurrTextStr & "," & _
CurrCell.Value
End If
Next CurrCell
Print #1, CurrTextStr
Next CurrRow
Close #1

End Sub


"cottage6" wrote:

Hello & help!!!
I'm all goofed up here, tried many things myself, and have failed miserably
(Excel 2000). Anyway, I need to export a range named EXPORTRANGE as .csv
format to C:\Lotus\Work\123, with the file name bake.csv. The range is
getting saved to the current directory (instead of C:\Lotus\Work\123), with
the name bakeadj.csv. I did see something about DIR returning the first found
file name in the directory, but couldn't figure out what to do about it;
bakeadj.csv is the first file. In addition to that, the exported range does
not put any commas in the file, just blank cells. Thanks for any help you
can give me. Totally messed up (and probably laughable) code follows:
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As String
Dim destpathname As String
Dim ColCount As Integer
Dim CurrCol As Integer
Dim filemask As String

destpathname = "C:\Lotus\Work\123\"
filemask = "bake.csv"
FName = Dir(destpathname & filemask, vbNormal)
ListSep = Application.International(xlListSeparator)

Range("EXPORTRANGE").Select
Set SrcRg = Selection
ColCount = SrcRg.Columns.Count
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrCol = 0
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrCol = CurrCol + 1
CurrTextStr = CurrTextStr & CurrCell.Value & IIf(CurrCol < _
ColCount, ListSep, "")

Next
Print #1, CurrTextStr
Next
Close #1

End Sub

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
exporting/saving recent files list vabki Excel Discussion (Misc queries) 3 December 17th 09 07:11 PM
Exporting / Saving as XML WalkToFreedom Excel Discussion (Misc queries) 3 October 22nd 08 01:11 AM
Exporting txt file ajshap1 Excel Discussion (Misc queries) 1 April 17th 07 05:44 PM
Exporting to csv file Geri Excel Discussion (Misc queries) 5 September 6th 05 02:48 PM
Exporting CSV file to unicode .txt file - " around strings Paul Excel Discussion (Misc queries) 1 June 14th 05 12:27 AM


All times are GMT +1. The time now is 03:39 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"