Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Does folder exist problem | Excel Programming | |||
How to: check if folder exist, if not, create | Excel Programming | |||
Create Folder and Text File in folder | Excel Programming | |||
How to check if a folder/directory exist using VBA | Excel Programming | |||
Create Folder / Copy Folder / Replace | Excel Programming |