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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Which quote - a " or a '

In either case you should be able to replace in the copy.
 

jeffandtamara

New Member
Joined
Apr 27, 2009
Messages
18
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.
 

Forum statistics

Threads
1,181,695
Messages
5,931,493
Members
436,790
Latest member
aelbaitam

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
Top