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!

Excel 2010 - late binding 1

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,558
US

I have this code in my VB 6 app, no References to Excel (I use late binding):
Code:
Option Explicit
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object

Private Sub cmdShow_Click()

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.ActiveSheet

On Error GoTo ErrH

recOne.Open txtSQL.Text, Cn

With xlApp
    For i = 0 To recOne.Fields.Count - 1
        .Sheets(1).Cells(1, i + 1) = recOne.Fields(i).Name
    Next
    .Sheets(1).Range("A2").CopyFromRecordset recOne
    For i = 1 To recOne.Fields.Count
        .Sheets(1).Columns(i).EntireColumn.AutoFit
    Next
    .Visible = True
End With

recOne.Close
End Sub
This code works fine, creates Excel file with the info I want.

But when I want to Save it, Excel wants to Save the file as Book1.xls, but it is Excel 2010 and it should save it as Book1.xls[red]x[/red]

What do I need to do for Excel to recognize the 2010 version and by default save files as xlsx?

Have fun.

---- Andy
 
Are you using the Save or the SaveAs Method in VBA code or are you saving it from the Excel UI? Checkout the options for the SaveAs Method.
 
Perhaps. Excel UI - click 'File' - Click 'options' - Click 'Save' - adjust the current 'Save files in this format' setting.
 

That was it - for some reason my Excel 2010 wanted to save files in xls format. I adjusted it for xlsx and now is OK :)

Thank you HughLerwill

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top