Saving to CSV VBA code glitch

Belfast Neil

New Member
Joined
Jul 7, 2016
Messages
11
Hi all,

I'm not a coder but am trying to get into using macros to speed up some of my workflows. I've recorded and tweaked a macro to edit down a sheet into a couple of basic columns. All seems to work fine in terms of saving it as a CSV in the last step but it also saves the original macros enabled workbook with the new CSV tab and changes. I want the original file left untouched and just a CSV file saved separately in the same path folder. Can anyone show me what I'm missing here? Any help greatly appreciated as I've messed about for 3 hours now trying to figure this out!

Sub MakeCSV()
'
' MakeCSV Macro
'

'
ActiveSheet.Copy After:=Sheets(1)
ActiveSheet.Name = "Price List CSV"
Cells.Select
Selection.Copy
Dim Name As String
Dim Spacer As String
Dim Description As String
Dim Filetype As String
Name = Range("A1").Value
Spacer = (" - ")
Description = Range("E1").Value
Filetype = (".csv")
FullName = Name & Spacer & Description & Filetype
Range("H3").Value = FullName

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.AutoFilter
Range("A:A,C:E").Select
Range("C1").Activate
Selection.Delete Shift:=xlToLeft
Rows("1:2").Select
Range("A2").Activate
Selection.Delete Shift:=xlUp
Columns("A:C").Select
Range("C1").Activate
Selection.AutoFilter
ActiveSheet.Range("$A$1:$C$712").AutoFilter Field:=3, Criteria1:= _
"=Standard", Operator:=xlOr, Criteria2:="="
Rows("2:2036").Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter

Dim relativePath As String
relativePath = ThisWorkbook.Path & Application.PathSeparator & FullName
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=relativePath, FileFormat:=xlCSV
MsgBox ("CSV file has been saved")
Application.DisplayAlerts = True
' ThisWorkbook.Close

End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
The code itself is not saving the original file. Are you by any chance working on a OneDrive or Sharepoint file ?
 
Upvote 0
Solution
The code itself is not saving the original file. Are you by any chance working on a OneDrive or Sharepoint file ?
Hi Alan, think that was the issue. My Desktop has been synced to OneDrive by our IT department and I didn't realise. Moved the file onto a local folder and my code actually works. Cheers for the input (y)
 
Upvote 0
No problem. Glad I could help and thanks for the feedback.
PS:
Most people have their Microsoft products to autosave when the files are on OneDrive set to autosave which is the default.
Onedrive and macros often don't play nice but if you wanted to persist you could try turning autosave off. It will most likely impact "all" your Onedrive files though.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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