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: 14
Default Create Folder If It Doesn't Exist

Hello,
I need help with a macro. Here is a background to my macro and what it
does. I have an excel workbook that will have a worksheet with headers in
row 1. The user will enter data below the headers in row 1. A command
button will also be on this worksheet. When the command button is pressed,
it will take all the data and output a .csv file to a particular location.
Here is the code for this:

Public Sub CreateCSV()
Dim iFile As Integer
Dim lRow As Long
Dim iCol As Integer
Dim sDelimiter As String
Dim sSpace As String
Dim sOutput As String

sDelimiter = ","
sSpace = " "

'Open the file for write
iFile = FreeFile
Open "C:\OUTPUT_FILE\" & ActiveSheet.Name & ".csv" For Output As #iFile

'parse the rows and columns
For lRow = 2 To ActiveSheet.UsedRange.Rows.Count
sOutput = ""
For iCol = 1 To ActiveSheet.UsedRange.Columns.Count

'build output string
If Cells(lRow, iCol) = "" Then
sOutput = sOutput & sSpace & sDelimiter
Else
sOutput = sOutput & Cells(lRow, iCol) & sDelimiter
End If
Next iCol

'write the output string to the file
sOutput = Left(sOutput, Len(sOutput) - 1)
Print #iFile, sOutput
Next lRow
Close #iFile

MsgBox "The .csv file is now located in the following folder -
C:\OUTPUT_FILE", vbInformation, "Upload Data"

End Sub

I am an accounting guy and don't have a lot of VB knowledge, most of this
code was not written by me. Here are the two problems I have with the macro:

1. How do I get this macro code to run when the command button on the
worksheet is clicked?

2. This workbook will be used by multiple users and not all users have the
folder "C:\OUTPUT_FILE\" in their C drive yet. How can I check to see if
this folder exists - if it does output the file - if it doesn't, create the
folder and then output the file?

Please help!!! Thanks!!!!

Ryan

 
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
Does folder exist problem Jeff Excel Programming 3 January 31st 05 03:22 PM
How to: check if folder exist, if not, create escorido[_2_] Excel Programming 2 July 9th 04 01:28 PM
Create Folder and Text File in folder Todd Huttentsine Excel Programming 2 April 29th 04 03:41 PM
How to check if a folder/directory exist using VBA wellie Excel Programming 1 March 1st 04 02:24 AM
Create Folder / Copy Folder / Replace Murray Outtrim[_2_] Excel Programming 0 February 24th 04 06:40 PM


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