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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,215,237
Messages
6,123,800
Members
449,127
Latest member
Cyko

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