+ Reply to Thread
Results 1 to 6 of 6

encoding a text file written by VBA

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    encoding a text file written by VBA

    Hi all,

    I have a peice of code that write an external file and puts various data in there. This works fine but because the encoding is incorrect the file will not work once it has been written, so does anybody know how I would add the correct encoding in the vba below? I know it needs to be ANSI but not sure where to add it.

    Please Login or Register  to view this content.
    Thanks for the help.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: encoding a text file written by VBA

    How is it wrong? Did you open it in Notepad and check?

  3. #3
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: encoding a text file written by VBA

    I did open and check and when I use 'Save As' and encode the file with ANSI the file size changes (Gets smaller), so this is my best guess as to why it wont work.

    Basically, the macro creates a .js file for the intranet here, allowing certain users to change information on the site header, but it wont work. Letter for letter it is the same as a test file I typed by hand that does work, so encoding is my first thought, and if I can find out how to specify the encoding using VBA I can eliminate that possibility if it still doesnt work.

    Thanks.
    Last edited by duckboy1981; 02-19-2009 at 12:39 PM.

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: encoding a text file written by VBA

    I am by no means certain but perhaps it is a result of the Windows line terminators being applied when you create the file. if the file is to be used on a Linux webserver it is perhaps conceivable that this could cause a problem. Windows uses the Cr-LF (Carriage Return/LineFeed) combination, whereas Linux just uses a LF (LineFeed). So what you could do is replace the CrLf with just a Lf eg:

    Please Login or Register  to view this content.
    Back everything up before you try this.

    Richard

    Alternatively, it could be because a unicode format is required for the webserver? Then:

    Please Login or Register  to view this content.
    Richard Schollar
    Microsoft MVP - Excel

  5. #5
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: encoding a text file written by VBA

    Thanks for the reply. I will give a bash tomorrow and get back to you. Just so ya know though, it's a windows webserver i'm using (IIS) and its UTF-8 it uses's, I made a mistake by saying ANSI above though.

  6. #6
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: encoding a text file written by VBA

    I then think it highly unlikely what I suggested will work (especially not the first bit) - the second would tend to increase the file size rather than reduce it too...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1