Using docmd.transferspreadsheet (1 Viewer)

GoodyGoody

Registered User.
Local time
Today, 01:42
Joined
Aug 31, 2019
Messages
120
Hi, I want to import an Excel SS containing 2 columns: RacerunnerNumber and Racetime. I'm allowing the user to select Excel files from 2003 onwards. However, when using the transferspreadsheet method it requires you to specify a SS type. Is there a way of me knowing which SS type it is when I import the object?

Code:
    Dim xlApp As Object
    Dim xlWb As Object
    Dim xlWs As Object

    Set xlApp = CreateObject("Excel.Application") 'the excel application
    strFileName = .SelectedItems(1) 'picking the selected file full path
    Set xlWb = xlApp.Workbooks.Open(strFileName, True, False)
    Set xlWs = xlApp.Worksheets(1)

Thanks in advance as ever
 

GoodyGoody

Registered User.
Local time
Today, 01:42
Joined
Aug 31, 2019
Messages
120

Thanks Adam. It came from elsewhere but I guess it's fairly standard naming conventions. Actually, been to these 2 threads but I can't see a solution anywhere which enables me to interrogate the selected file for it's Excel version so I can use the right option on the transferspreadsheet command. Or am I missing something? :) Probably!
 

vba_php

Forum Troll
Local time
Yesterday, 19:42
Joined
Oct 6, 2019
Messages
2,880
Actually, been to these 2 threads but I can't see a solution anywhere which enables me to interrogate the selected file for it's Excel version so I can use the right option on the transferspreadsheet command.
*interrogate*? what, are we working for the NSA or CIA now? :p the *interrogation* you speak of can be done simply by looking at the file extension and selecting the appropriate [number] as the last byte/s of the SpreadSheetType argument in that function. that link I gave you should also give an explanation of what file extensions belong to what spread sheet type. did you see that? as far as being concerned over the excel application "version", that's kind of irrelevant because virtually every excel version after 2007 has been able to open all file types sourcing all the way back to the birth of excel (I think). e.g. - xls, xlsx, xlsm, xml, etc...
 

GinaWhipp

AWF VIP
Local time
Yesterday, 20:42
Joined
Jun 21, 2011
Messages
5,899
Hi, I want to import an Excel SS containing 2 columns: RacerunnerNumber and Racetime. I'm allowing the user to select Excel files from 2003 onwards. However, when using the transferspreadsheet method it requires you to specify a SS type. Is there a way of me knowing which SS type it is when I import the object?

Code:
    Dim xlApp As Object
    Dim xlWb As Object
    Dim xlWs As Object

    Set xlApp = CreateObject("Excel.Application") 'the excel application
    strFileName = .SelectedItems(1) 'picking the selected file full path
    Set xlWb = xlApp.Workbooks.Open(strFileName, True, False)
    Set xlWs = xlApp.Worksheets(1)

Thanks in advance as ever
This is correct when using the TransferSpreadsheet method. A way to give Users and option can be done by using Excel Automation to which I see you have a start and letting your Users pick the file by using FileDialog. to select the file.


Then you can not only control the extensions but allow XLS and XSLX.
 

GoodyGoody

Registered User.
Local time
Today, 01:42
Joined
Aug 31, 2019
Messages
120
Thanks Gasman. That was what I was looking for. I know there is an argument for the transferspreadsheet method but you need to know what format of Excel it is in for it to work and this would seem to be the answer I was looking for. Thanks again
 

Users who are viewing this thread

Top Bottom