• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 46
  • Last Modified:

Excel VBA: Validate Code Page Identifier Exists

I am creating query tables in VBA. (See a sample from Ejgil below.) Nonetheless, the query table asks for a .textfileplatform. Basically this is one of 152 code page identifiers installed in Windows. Sometimes Windows may or may not have the one you are looking for. Example 1252 below is a 'Western European' Code page identifier, which for whatever reason may/may not be installed on a machine in Canada etc., What VBA would I use to validate a code page identifier exists?

 With Selection.QueryTables(1)
        .Connection = "TEXT;" & CsvFileName
        .TextFilePlatform = 1252
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 3, 3)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With

More on Code Page Identifiers is at this link ---> https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx
  • 2
  • 2
1 Solution
Code Pages are stored in C_XXXXX.nls files (in windir\system32 folder). You can check existence of file:
Public Function chk_CP(CP As String) As Boolean
Dim r As String
     r = Environ("windir") & "\system32\C_" & CP & ".nls"
     r = Dir(r)
     chk_CP = False
     If Len(r) > 0 Then chk_CP = True
End Function
ouestqueAuthor Commented:
Really Cool als315. Just some clarification. If someone is running Windows 64 bit instead of 32 bit, would the path be different. (i.e., "/system64" instead of "system32" etc.,) If so what would the new path be?
They are always in system32
ouestqueAuthor Commented:
Thanks als315!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now