New book as CSV

kidalex

New Member
Joined
Aug 30, 2022
Messages
1
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hi, I need your help please.
I need to generate a macro that opens a new workbook, fills in some data in this new workbook, and I need to save it as CSV.
For the new workbook, I have created an object. The steps I perform are as follows.

'I create object
Set Excel_App = CreateObject("Excel.Application")
Excel_App.Visible = True
Excel_App.Workbooks.Add

'I fill new workbook
With Excel_App
Cell_Value = 2
.ActiveCell.FormulaR1C1 = Cell value
End With

When I try to save the new workbook, it doesn't save the new workbook, but it triggers the macro that I run as CSV.
Can you help me with the code?


Translated with www.DeepL.com/Translator (free version)
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
What application is hosting this VBA code? If this code is in an Excel file there is no need to create a new instance of Excel. You also do not the code you are suing to save the workbook. The phrase "the macro that I run as CSV" did not translate well because I have no idea what that means.

Use this code instead:
VBA Code:
   Dim NewCSV As Workbook
   
   Set NewCSV = Workbooks.Add
   NewCSV.Worksheets(1).Range("A1") = "Hello world!"
   
   NewCSV.SaveAs Filename:=ThisWorkbook.Path & "\MyNewFile.csv", FileFormat:=xlCSV
   NewCSV.Close savechanges:=False
 
Upvote 0

Forum statistics

Threads
1,215,706
Messages
6,126,340
Members
449,311
Latest member
accessbob

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