VBA Code to Copy & Paste Values as is on CSV file format

kkoruni

New Member
Joined
Jul 18, 2017
Messages
23
Hello,
I need your help with incorporating (Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False) to my vba below.
The goal is to copy & paste values as entered before exporting to a new csv file type. Thank you for any help provided.

VBA Code:
Private Sub CommandButton1_Click()
Dim WB_CSV As Workbook
Dim MyFileName As String, MyFolder As String
MyFileName = Trim(Sheets("PROF_Data_Capture").Range("B2").Value)
MyFolder = "C:\My Data\Policies\Employees"

If MyFileName <> "" Then
With CreateObject("Scripting.FileSystemObject")
If Not .FolderExists(MyFolder) Then
MsgBox "Folder not found:" & vbCr & MyFolder, vbOKOnly Or vbExclamation, "File Folder Error"
Exit Sub
End If
End With

MyFileName = Split(MyFileName, ".")(0) & ".csv"
With Sheets("PROF_Data_Capture")
.Unprotect
.Copy
Set WB_CSV = ActiveWorkbook
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End With

With WB_CSV.Worksheets(1)
.Range("A1:B36").Value = .Range("A1:B36").Value
End With

Application.DisplayAlerts = False
WB_CSV.SaveAs Filename:=MyFolder & "\" & MyFileName, FileFormat:=xlCSV
Application.DisplayAlerts = True
WB_CSV.Close False

MsgBox "CSV file " & MyFileName & " created in folder:" & vbCrLf & vbCrLf _
& MyFolder, vbOKOnly Or vbInformation, "File Export"
End If
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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