PDA

View Full Version : Save workbooksheet as .CSV with some variables



rolandv
04-30-2019, 03:19 AM
Hi all, I'm Roland and I'm new to this forum & VBA, hope someone can help me with this challenge.

I've got a workbook with multiple sheets, which is used to facilitate an operational process for a warehousing activity. I'm almost done with the "tool" except for one more thing.
I am looking for a vba code to save the sheet called "Input CW1" as CSV. This is easy with a regular code, however I would like to provide the operations with some options to improve the processing. These required options are as follows:

- I want the file to have the text in cell B2 of tab "Output CW1" as title. So “text B2.csv”.
- I want the file to be saved in the location that is put in cell B3 of the tab "Output CW1".

The macro should be attached then to the button in the tab “Output CW1”, so the macro has to be setup so it switches between tabs.

Since I have little to zero knowledge of VBA I hope someone can support me over here.

Roland

georgiboy
04-30-2019, 03:46 AM
Hi Roland, welcome to the forum.

Maybe something like this would help:

Sub SaveCSV()
Dim flName As String, flPath As String
Dim strFullname As String

flPath = Sheet4.Range("B3").Value
flName = Sheet4.Range("B2").Value

strFullname = flPath & flName

Application.DisplayAlerts = False
Sheets("Input CW1").Copy
ActiveWorkbook.SaveAs Filename:=strFullname, FileFormat:=xlCSV, CreateBackup:=True
ActiveWorkbook.Close
Application.DisplayAlerts = True

End Sub

Your file path will need to end with a \ for it to work.

Hope this helps

rolandv
04-30-2019, 04:01 AM
That works, many thanks :)