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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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