Link to home
Start Free TrialLog in
Avatar of alevin16
alevin16Flag for United States of America

asked on

Importing select fields from Excel into Access BUT the excel sheet has a space in the name

Hello All

I have a project where I have to import certain data from excel spreadsheets into Access.  I have everything working except for one snafu.  Some of the Excel workbooks have multiple sheets and those sheets have spaces in the name like Page 1, Page 2, etc.

These Excel workbooks are created by converting pdfs.

The program I am using is great, it converts them exactly as I need them except for the space in the sheet name.

I cannot manually change the sheet names because there are over 5000 individual pdfs (with anywhere from 1 to 8 sheets each) so I really need to automate this.

I have tried putting single quotes around the name and range ('Page 1!A8:A8'), single quotes around just the page name ('Page 1'!A8:A8), and all sorts of other things (like brackets).

Oh I am using the docmd.transferspreadsheet acimport (this was my latest try):

mysheetname was already set to Page 1 earlier since during the loop it will have to be set to Page 2 then Page 3 etc
RangeExcel = "!A8:A8"
ComboSR = "[" & mySheetName & "]" & RangeExcel
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Test of Importing QUotes", "C:\Users\New Laptop\Desktop\Optigrate\QuotesPDF\PdfToExcel\PdfToExcel\Q-2014-0929-MUn-1", False, ComboSR

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alevin16

ASKER

I will give this a shot.  It looks promising!

Thanks I will report back shortly

Andy
please post a representative sample workbook
I wonder if Excel does something like Access does.  Whenever you use an object name that includes invalid characters, Access converts them internally to the underscore and that allows Access to create event procedures with valid names.  For example, the click event for a text box named [my #$ Bad Name] Becomes Click_my____Bad_Name.  So, that string of invalid characters gets converted to four underscores and then one for the space between bad and name.

I would try simply substituting "_" for space using the replace() function and see what happens.
You can also attach the worksheets to your database and look at the connection string and the table name.