VBA User Form help - How to save current worksheet as a csv file?

heliraptor

New Member
Joined
Jan 12, 2006
Messages
19
Hi,

I'm working on a workbook (contains two sheets) that users can log certain data with a user form I created.

I'm new to vba but doing pretty well, however one of the areas I'm struggling with is on the form creating a button, and when the user clicks it it saves the active work sheet to a specified location and automatically navigates to that location in the save as dialog and offers up the correct file name and elects .csv as the format.

So, I have the save as button called 'btnSaveAs' and I want the code to run when the user clicks it.

The intention is clicking it will open up the SaveAs dialog box and navigate to C:\AIMS\Test Folder\

I want the suggested filename to be "AIMS Test" and to be in the .csv format.

Seem's to be pretty standard function, but I cant figure it out, and I've searched far and wide. Every suggestion I've seen either doesn't work out, or I can't adapt the code to my needs.

Any assistance appreciated, this has me stumped !!

Cheers

Lee
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Thanks,

I'll combine the two and give it a go.

I'll report back with the combined code once its working (fingers crossed)
 
Upvote 0
Hi

All okay so far....

I used this code on the click of a button

Private sub btnSaveAs_Click()

ActiveWorkbook.SaveAs Filename:= _
"c:\AIMS Test\AIMS Test.csv", FileFormat:=xlCSV _
, CreateBackup:=False

End Sub

This saved the current worksheet (not workbook) to a csv file which is what I was after, however it offered me (and wasn't expected) any confirmation, unless I saved it again, and then I got the standard windows replace file dialogue box.

Is there a way I can receive confirmation via message box that the file has been saved ??

Either that or get the save as dialog box to open and automatically point to the required location and filename?

I moved one step on fm this today, and added code to hide the workbook and show the form as a user opens the sheet. This worked well. After saving, the user can close down the sheet with an exit button and I've added code to automatically shut down the application, but then I receive a standard application dialog asking me if I want to save the changes to AIMS Test.csv.

Is there a way I can apply code to ignore the standard dialog box? If so do I add it to the workbook module of the form?

Thanks for the advice so far.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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