View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.newusers
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 6
Default Substituting a xls format with a xlsx format file

Hi:

I have piece of VBA code that populates a Word UserForm combobox from a
external source (named range in an Excel file.) It
works perfectly as is with Word2003 or Word2007 using a .xls Excel file
extension.

Here is the code:

Private Sub UserForm_Initialize()
Dim strOffice As String
Dim i As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
strOffice = "mySSRange"
'Open the file containing the Office Locations
Set db = OpenDatabase(ThisDocument.Path & Application.PathSeparator &
"GetData.xls", False, False, "Excel 8.0")
'Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `" & strOffice & "`")
'Determine the number of retrieved records
With rs
.MoveLast
i = .RecordCount
.MoveFirst
End With
'Set the number of Columns = number of Fields in recordset
cmbOfficeLocations.ColumnCount = rs.Fields.Count
'Load the combobox with the retrieved records
cmbOfficeLocations.Column = rs.GetRows(i)
'Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub

However, if I save the xls file as a Excel2007 format file with and xlsx
extension and change "GetData.xls" to "GetData.xlsx" I get a RTE 3274
"External table is not in the expected format." If I change "Excel 8.0" to
"Excel 12.0" I get a RTE 3170 Could not find installable ISAM"

Can anyone tell how I would make this or similiar code work with an
Excel2007 format file? Thanks.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~