Macro to convert data to text and save as csv file

pip67

New Member
Joined
Oct 2, 2008
Messages
14
Hi Guys,

I am trying to get a macro that highlights the active worksheet (can have many rows of data from 1 to 20k) then converts the data to Text and the the user is prompted to save the workbook as a csv file with a different name each time.

Any help is most appreciated as I have a limited knowledge of vb.

Thanks again

Pip
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Wouldn't the following suffice?

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] SaveAsCSV()

    [color=darkblue]Dim[/color] strFileName [color=darkblue]As[/color] [color=darkblue]Variant[/color]

    strFileName = Application.GetSaveAsFilename( _
        InitialFileName:=ActiveWorkbook.Name, _
        Filefilter:="Comma Seperated Files (*.csv), *.csv", _
        Title:="Save As")
        
    [color=darkblue]If[/color] strFileName = [color=darkblue]False[/color] [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Sub[/color]
        
    ActiveWorkbook.SaveAs Filename:=strFileName, _
            FileFormat:=xlCSV, CreateBackup:=[color=darkblue]False[/color]
            
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0
Hi thanks for you reply it works perfectly. One quick question if I may. where in the code could I place something that would format the entire worksheet to Text format if at all possible?

Sorry to be a pain and thanks again!!
 
Upvote 0
You can place this line of code at the beginning...

Code:
Cells.NumberFormat = "@"
 
Upvote 0
Hi Domenic,

Thats absolutely brilliant thanks for your help and have a good week!!!!

Cheers
Pip
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,225
Members
452,896
Latest member
IGT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top