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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
you can use vba codes to revise the sheet name prior to importing..
sub renameSheets(excelFile as string)
dim xlObj as object, j as integer

set xlObj=createobject("excel.application") excelfile
      with xlObj
            for j=1 to .worksheets.count
                   .worksheets(j).Name = replace(worksheets(j).Name, " ", "_")
      end With
end sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alevin16Author Commented:
I will give this a shot.  It looks promising!

Thanks I will report back shortly

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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.