Excel saving a file witout quotations

5h1v

Board Regular
Joined
Oct 11, 2012
Messages
69
Hey,

I am trying to make some VBA that saves one row of data from a spreadsheet and saves it as a PRN file which I can do but it adds quotation marks to the start and end of every row, how do I go about removing them without having to do it manually?

Here is my code;

Code:
   Sheets("Olink").Select
    Columns("P:P").Select
    Range("P188").Activate
    Selection.Copy
    Sheets.Add after:=ActiveSheet
    Worksheets.Add().Name = "DD"
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    myFolder = Application.GetSaveAsFilename(fileFilter:="PRN (*.prn), *.prn")
    ActiveWorkbook.SaveAs Filename:=myFolder, FileFormat:=xlCSV, CreateBackup:=False
End Sub
 
Using the techniques shown here: https://analysistabs.com/vba/vba-write-string-text-file-without-quotes/

The code would look something like this:
Code:
Sub ExportData()

    Dim lr As Long
    Dim r As Long
    Dim myFileName As String
    Dim cellValue As Variant
    
    Sheets("Olink").Select
    
'   Find last row with data in column P
    lr = Cells(Rows.Count, "P").End(xlUp).Row
    
'   Prompt for full file path and name
    myFileName = Application.GetSaveAsFilename(fileFilter:="PRN (*.prn), *.prn")
    
'   Create new file
    Open myFileName For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
    
'       Loop through all rows in column P
        For r = 1 To lr
'           Capture value of cell
            cellValue = Cells(r, "P").Value
'           Write to text file
            Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , cellValue
'       Move to next row
        Next r
'   Close text file
    Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 

    MsgBox myFileName & " created"

End Sub
Note that there isn't any need to copy the data to a new sheet to do this. We can do it from column P on the Olink sheet.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Just tried this and it works perfectly, thank you so much this will save me so much time removing the excess characters.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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