Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a quoted string to a text file in VBA.

Status
Not open for further replies.

AlbertCamus

Programmer
Sep 17, 2007
2
US

Hello,

Is anybody familar with a way to print or write a string to a text file in VBA, with the special case that the string contains a section which needs to be quoted as well as a section that does not need to?

If I wanted to write the following example to a text file, how would it be accomplished?

example: The author notes that, "certain people have trouble asking for help", while others do not.

If I wanted that line to appear exactly as it is typed, what would I do?

Thanks,
 
Code:
Sub Write_Quoted_Strings()
   Dim file_name as string, aline As String
   
   file_name = "C:\Documents and Settings\WinblowsME\Desktop\Quoted_Strings.txt"

   Open file_name For Output As #1
      aline = "The author notes that, " & Chr(34) & _
              "certain people have trouble asking for help," & Chr(34) & " while others do not."
      Print #1, aline
      
      aline = "The author notes that, ""certain people have trouble asking for help,"" while others do not."
      Print #1, aline
   Close #1
End Sub
 
strA="The author notes that,"
strA = strA & """
strA="certain people have trouble asking for help"
strA = strA & """
strA = strA & ", while others do not."

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top