Import Text Files with VBA- How to set TextFilePlatform to a code page

kienleong

New Member
Joined
Mar 17, 2010
Messages
13
Hello

I am writing a macro that changes the filepath for an existing text file import as a QueryTable. I want to set the connection parameters to variables and reapply them with a different filepath.

Code:
Dim DataType() as Variant
Dim Platform as Integer
Dim TableCell As Range
Dim TabDelimiter as Boolean, CommaDelimiter as Boolean

Set TableCell = Wksht.Range("A10")           
ReDim DataType(1 To UBound(TableCell.QueryTable.TextFileColumnDataTypes))
            
DataType = TableCell.QueryTable.TextFileColumnDataTypes
TabDelimiter = TableCell.QueryTable.TextFileTabDelimiter
CommaDelimiter = TableCell.QueryTable.TextFileCommaDelimiter
Platform = TableCell.QueryTable.TextFilePlatform

With Wksht.Range("A10").QueryTable
    .Connection = ConnectPath
    .TextFileColumnDataTypes = DataType
    .TextFilePlatform = Platform
    .TextFileParseType = xlDelimited
    .TextFileTabDelimiter = TabDelimiter
    .TextFileCommaDelimiter = CommaDelimiter
End With

This works fine for all parameters except TextFilePlatform. I want to set it to the code page (eg. 437 for IBM-PC, 65000 for Unicode)

VBA help says that

XlPlatform can be one of these XlPlatform constants.
xlMacintosh
xlMSDOS
xlWindows

and .QueryTable.TextFilePlatform has a number that refers to one of these constants.

However, the macro recorder assigns a code page number to the TextFilePlatform property.

How do I assign a variable to original code page and not have it reset to the default Windows (ANSI)?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

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