private sub to save an excel sheet as separate csv

VectorW2

New Member
Joined
Sep 11, 2013
Messages
36
Office Version
  1. 365
  2. 2010
I have a private sub that calls a macro (works):

Case "Save":
Call SaveAsCSV

However, I would prefer to not have the "SaveAsCSV" be a public macro and just add it to the private sub

The public "SaveAsCSV" macro:

Sub SaveAsCSV()

'

' SaveAsCSV Macro

'



'

Sheets("Gama Uploadable").Select

ActiveWorkbook.SaveAs Filename:= _

"C:\My Documents\Upload Files (2022)\" & Range("GamaFileName").Value & ".csv", _

FileFormat:=xlCSVUTF8, CreateBackup:=False



End Sub

The public sub also renames the sheet inquisition a unique name based on the value of a cell. That cell has a formula in it.

If you can help me, I would greatly appreciate it.

Thank you in advance.
 

Attachments

  • Public Sub.jpg
    Public Sub.jpg
    47.4 KB · Views: 8
  • Private Sub.jpg
    Private Sub.jpg
    190.8 KB · Views: 8

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
What module is the SaveAsCSV code in?
 
Upvote 0
Silly question but how do I tell? The private sub is on sheet one. The second sheet takes the data from the sheet one; calculates and converts it. The formula and range to rename the third sheet is also located on here on the second sheet. The private sub clears the first sheet. Then copies the second sheet and pasted special onto the third sheet.

The third sheet is to be saved as csv in a specific location, with a specific and unique name.

There can be no formulas on it as it is needed as text only for upload. I hope this answers your question.
 
Upvote 0
If you goto the code & look at the title bar of the VB editor it will have something like [Module1(code)] what does that bit say?
 
Upvote 0
Vbaproject(1.6.22 Template - 6I to Gama.xlsm)
Vbaproject(personal.xlsb)
Microsoft excel objects
Modules
Module1 —located here—
 
Upvote 0
In that case instead of Call SaveAsCSV you can use Run "Module1.SaveAsCSV"
 
Upvote 0
No that allows you to run a private macro.
 
Upvote 0
I hoped to just add to the private sub somehow. I’ve tried many different things…but none worked. It works when calling it but not if I try to include it in the private sub code.
 
Upvote 0
I will try your suggestion and see what happens. Thank you for your time and help. If i can get that piece to work in the private sub…i would prefer it.
 
Upvote 0

Forum statistics

Threads
1,214,847
Messages
6,121,911
Members
449,054
Latest member
luca142

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