VBA Writing a Text File w/ embeded " character

jeffandtamara

New Member
Joined
Apr 27, 2009
Messages
18
Help.....
I am writing out a Fixed record length text file. The Text has to be a fixed length. Life was good until a user input 61" as part of the Comment field. The field is defined as 30 characters.

Code to write it out was :
Comments = String(30 - Len(Left(ActiveSheet.Cells(Row, 31), 30)), " ") & Left(ActiveSheet.Cells(Row, 31), 30)

Write Statement:
Write #1, Lot, LotStatus, ... , Comments, ...

OUTPUT:
," HAD TROUBLE WITH SCRAP 61""",

For some reason I am getting a 31 Character length field, because of the embeded quotation mark. I have tried all kinds of text manipulation. When I do a Len(comments) on the field, I get a length of 30, but when it writes out it wants to add an extra quatation mark that makes the field 31 characters not 30.... Any ideas???
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Which quote - a " or a '

In either case you should be able to replace in the copy.
 
Upvote 0
It is the " double quote character. The comment was referring to Inches, so I don't want to not allow the abreviation for inches in the comment section.

The problem comes in the write procedure; I am using a comma delimited format and the text fields are comma delimited with double quotes around the entire field.... I need a trick to allow the double quote character to be part of the comment with out tripping up the comma delimited format....which until now was doing exactly what I needed.
 
Upvote 0

Forum statistics

Threads
1,213,563
Messages
6,114,332
Members
448,566
Latest member
Nickdozaj

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