#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 989
Default Input Box

Can someone show me how to use VBA to collect part of a folder and file name
from an input box?

e.g. Const CSVFile As String = "Z:\FILES\ACCOUNTING\PAYROLL\DAILY PROGRESS
REPORTS (DPRs)\WE 5-9-10\WE 5-9-10.csv"

I would like to use an input box to change the date of the folder €śWE
5-9-10€ť and the file €śWE 5-9-10.csv€ť

This is the scenario€¦ I have excel files that are emailed to me daily,
typically four to six separate workbooks per day. The information in the
spreadsheets is for payroll, so having all the data in one workbook at the
end of the week makes it much easier to process. I patched together the
following VBA to append each workbooks data to a .csv file, but there has to
be a better way to do this. Any help offered would be greatly appreciated.

VBA I'm currently using:

Sub Append2CSV()
Dim tmpCSV As String 'string to hold the CSV info
Dim f As Integer
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"

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

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Input Box

If I understand correctly you want the csvfile name to be created dynamically
from the date input..Try the below


Dim CSVFile As String, varData As Variant

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


--
Jacob (MVP - Excel)


"Mark" wrote:

Can someone show me how to use VBA to collect part of a folder and file name
from an input box?

e.g. Const CSVFile As String = "Z:\FILES\ACCOUNTING\PAYROLL\DAILY PROGRESS
REPORTS (DPRs)\WE 5-9-10\WE 5-9-10.csv"

I would like to use an input box to change the date of the folder €śWE
5-9-10€ť and the file €śWE 5-9-10.csv€ť

This is the scenario€¦ I have excel files that are emailed to me daily,
typically four to six separate workbooks per day. The information in the
spreadsheets is for payroll, so having all the data in one workbook at the
end of the week makes it much easier to process. I patched together the
following VBA to append each workbooks data to a .csv file, but there has to
be a better way to do this. Any help offered would be greatly appreciated.

VBA I'm currently using:

Sub Append2CSV()
Dim tmpCSV As String 'string to hold the CSV info
Dim f As Integer
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"

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

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Input Box

Thank you Jacob.

Do you know of way to save(append) to an excel file, rather than .csv?

-Mark Elkins

"Jacob Skaria" wrote:

If I understand correctly you want the csvfile name to be created dynamically
from the date input..Try the below


Dim CSVFile As String, varData As Variant

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


--
Jacob (MVP - Excel)


"Mark" wrote:

Can someone show me how to use VBA to collect part of a folder and file name
from an input box?

e.g. Const CSVFile As String = "Z:\FILES\ACCOUNTING\PAYROLL\DAILY PROGRESS
REPORTS (DPRs)\WE 5-9-10\WE 5-9-10.csv"

I would like to use an input box to change the date of the folder €śWE
5-9-10€ť and the file €śWE 5-9-10.csv€ť

This is the scenario€¦ I have excel files that are emailed to me daily,
typically four to six separate workbooks per day. The information in the
spreadsheets is for payroll, so having all the data in one workbook at the
end of the week makes it much easier to process. I patched together the
following VBA to append each workbooks data to a .csv file, but there has to
be a better way to do this. Any help offered would be greatly appreciated.

VBA I'm currently using:

Sub Append2CSV()
Dim tmpCSV As String 'string to hold the CSV info
Dim f As Integer
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"

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

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

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
How to input pictures automatically based on cell input? bsharp Excel Worksheet Functions 9 May 30th 09 07:16 AM
input in number form is being multiplied by 1000 when i input. jweinograd Excel Discussion (Misc queries) 4 April 16th 07 11:18 PM
Have user input converted to uppercase in same cell as input? Shannonn New Users to Excel 1 June 20th 06 03:19 AM
How do I add input data in the input ranges in drop down boxes. oil_driller Excel Discussion (Misc queries) 1 November 9th 05 10:31 PM
=SUMIF(Input!H2:H718,AZ19,Input!E2:E685)AND(IF ALex Excel Worksheet Functions 2 March 14th 05 09:19 PM


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