LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default save(append) to an excel file

The following code will copy(append) a range to a .csv file. I am looking for
a way to save(append) to an excel file, rather than .csv?

Sub Append2CSV()
Dim tmpCSV As String 'string to hold the CSV info
Dim f As Integer
Dim CSVFile As String, varData As Variant
Dim myRng As String
Dim myRng2 As String
Dim myRng3 As String

myRng = Application.InputBox("Enter a number")

'Const CSVFile As String = "Z:\FILES\ACCOUNTING\PAYROLL\DAILY PROGRESS
REPORTS (DPRs)\WE 5-9-10\WE 5-9-10.csv" 'replace with your filename

f = FreeFile
myRng2 = "A2:N"
myRng3 = myRng2 & myRng

varData = InputBox("Enter Date")
If Not IsDate(varData) Then MsgBox "Invalid Date": Exit Sub

CSVFile = "Z:\FILES\ACCOUNTING\PAYROLL\DAILY PROGRESS REPORTS " & _
"(DPRs)\WE " & Format(CDate(varData), "m-d-yy") & "\WE " & _
Format(CDate(varData), "m-d-yy") & ".csv"

MsgBox CSVFile

Open CSVFile For Append As #f
tmpCSV = Range2CSV(Range(myRng3))
Print #f, tmpCSV
Close #f
End Sub

Function Range2CSV(list) As String
Dim tmp As String
Dim cr As Long
Dim r As Range

If TypeName(list) = "Range" Then
cr = 1

For Each r In list.Cells
If r.Row = cr Then
If tmp = vbNullString Then
tmp = r.Value
Else
tmp = tmp & "," & r.Value
End If
Else
cr = cr + 1
If tmp = vbNullString Then
tmp = r.Value
Else
tmp = tmp & Chr(10) & r.Value
End If
End If
Next
End If

Range2CSV = tmp
End Function

Thank you,

Mark


 
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
Is it possible to Append worksheets in the same excel file? Angie33 Excel Discussion (Misc queries) 3 August 7th 08 04:58 PM
Append Excel Sheet from constantly updating delimited text file Ker G Setting up and Configuration of Excel 1 April 8th 08 09:33 PM
how can I Append values to an existing excel file. viv New Users to Excel 0 March 21st 07 11:25 AM
Trying to Append File using the example in excel but not working Susan Hayes Excel Programming 2 December 14th 05 12:35 AM
Append the data given in diff sheets of an Excel File to one sheet sansk_23 Excel Worksheet Functions 3 May 10th 05 02:00 AM


All times are GMT +1. The time now is 04:42 PM.

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

About Us

"It's about Microsoft Excel"