MS Access Forum / Modules / DAO / VBA / May 2008
transfer spreadsheet with spaces in the sheetname
|
|
Thread rating:  |
Coby - 15 Feb 2008 19:54 GMT I am using the transfer spreadsheet command, but whenever the Excel spreadsheet has spaces in the name, I don't know how to deal with that therefore is doesn't work.
For instance: DoCmd.TransferSpreadsheet acImport, 8, "Temp_SB_Pricing", strUsFile, False, "Pricing!A2:U300" - This Works Fine
BUT
For instance: DoCmd.TransferSpreadsheet acImport, 8, "Temp_SB_Pricing", strUsFile, False, "Pricing 2008!A2:U300" - DOES NOT WORK - and I am pretty sure it is because of the space between pricing and 2008 in the sheet name.
Since I cannot dictate the sheet name from the source I get them from, does anyone know how to deal with this?
Thank for all of your help. Coby.
PatK - 15 Feb 2008 20:16 GMT This may be simplistic, but may be worth a try. What happens if you replace every space in the file name with %20? In other words, parse for spaces and replace with %20. I know the gurus here would probably have a better approach.
Patk
> I am using the transfer spreadsheet command, but whenever the Excel > spreadsheet has spaces in the name, I don't know how to deal with that [quoted text clipped - 16 lines] > Thank for all of your help. > Coby. HatesIT - 15 Feb 2008 20:40 GMT not tested "[Pricing 2008]!A2:U300" hth
> I am using the transfer spreadsheet command, but whenever the Excel > spreadsheet has spaces in the name, I don't know how to deal with that [quoted text clipped - 16 lines] > Thank for all of your help. > Coby. Coby - 15 Feb 2008 21:47 GMT On Feb 15, 12:40 pm, HatesIT <Hate...@discussions.microsoft.com> wrote:
> not tested > "[Pricing 2008]!A2:U300" [quoted text clipped - 22 lines] > > - Show quoted text - I have now tried: "[Pricing 2008]!A2:U300" Chr(33) & "Pricing 2008" & Chr(33)& "!A2:U300" "Pricing%202008!A2:U300" "Pricing"& %20 & "2008!A2:U300" "Pricing"& Chr(32) & "2008!A2:U300" And none of those work . . . maybe I am doing something else wrong because it sure seems like the suggestions you all have proposed should logically work??
I appreciate the help. I will keep trying. Coby.
fredg - 15 Feb 2008 22:12 GMT > I am using the transfer spreadsheet command, but whenever the Excel > spreadsheet has spaces in the name, I don't know how to deal with that [quoted text clipped - 16 lines] > Thank for all of your help. > Coby. Using my testing worksheet name of "Pricing 2008!A1:I10"
your "Pricing 2008!A2:U300" should work.
I'll assume that your strUsFile is the same in both instances. Are you sure the spreadsheet type is 8?
What error message do you get? Why do you assume it's the space in the worksheet name causing the failure? Is "Temp_SB_Pricing" an existing table? Perhaps there is a problem with the existing field names not matching the imported spreadsheet names. Change your table name code to "tblImportTest" and see if the data is imported into this new table.
 Signature Fred Please respond only to this newsgroup. I do not reply to personal e-mail
Coby - 15 Feb 2008 22:35 GMT > > I am using the transfer spreadsheet command, but whenever the Excel > > spreadsheet has spaces in the name, I don't know how to deal with that [quoted text clipped - 40 lines] > > - Show quoted text - Thanks for the help, Fred!
The error I am getting is "Syntax error (missing operator0 in query expression 'Pricing 2008$A2:U300'. The message shows a $ in place of the ! that I actually used.
I am not sure if that means anything.
Also, I am not importing into an existing table. And, I am just going with the field names that are automatically assinged. I am using spreadsheet type 8
The strUsFile is the same in both instances: that is the directory path and file name.
The only reason I think it has to do with the spaces is because when I rename the worksheet name without spaces, then try it referring to the name without spaces. . . it works. Also, the problem only exists when I am dealing with spreadsheets with spaces in the names.
Perhaps, there is some other syntax that needs to be used ie, brackets, apostrophe, etc. that the worksheet object requires to refer to it whenever it has spaces.
I don't know . . . just thinking outloud to bounce that off of what you think.
Thanks,
Coby.
PatK - 15 Feb 2008 23:42 GMT It is my belief that these two things are true, when it comes to importing spreadsheets:
- The "range" parameter must be just that, a Range. A range cannot include the worksheet name, because, aside from my next bullet, only the first tab in the worksheet can ever be imported. Thus, having page "prefix" would be moot
- You can define a named region, using the Define Name function in excel, and have it map to the cells in any worksheet/range. For example, defining a name ranged called "Pricing2008", and point that name at cells A1:Z999 (assuming this is your range of data to import). A defined name cannot have a space, I believe, so the same problem would even exist, there. But that may also be saying something.
I just tested the above, and these two statements work:
DoCmd.TransferSpreadsheet acImport, , "Price 2008", "C:\myfile.xls", True, "test"
where TEST is a defined named range in the excel file. This also works:
DoCmd.TransferSpreadsheet acImport, , "Price 2008", "myfile.xls", True, _ "A1:X999"
Deduction tells me (and I am likely wrong, so I am open to calibration, as this would solve a problem I also have been messing with), but you must either have a range (without a worksheet prefix), ie CRx:CRx (CR=your column/row, x=number range), or a defined name. And I think that is it.
If anyone finds out anything different, let me know!
Patk
> > > I am using the transfer spreadsheet command, but whenever the Excel > > > spreadsheet has spaces in the name, I don't know how to deal with that [quoted text clipped - 71 lines] > > Coby. PatK - 15 Feb 2008 23:48 GMT Just to clarify my second belief: You can have a filename prefix..just not one with a space. I believe this is the only way it will work because, for example "Price2008!A2:U300" is, in reality, a defined named range. Again, just my guess and I am open to calibration.
Patk
> It is my belief that these two things are true, when it comes to importing > spreadsheets: [quoted text clipped - 104 lines] > > > > Coby. fredg - 16 Feb 2008 01:22 GMT > Just to clarify my second belief: You can have a filename prefix..just not > one with a space. I believe this is the only way it will work because, for [quoted text clipped - 111 lines] >>> >>> Coby. Pat, See my replies to Colby. You can include a space in the worksheet name. Colby has a problem with it in his import. I did not have a problem with it in my test import. I just checked the Ascii chart and chr(160) is also space. Access uses chr(32), so that may be why the Access import doesn't find the worksheet.
Perhaps if Colby see this message he can try:
"Pricing" & chr(160) & "2008!A2:U300"
 Signature Fred Please respond only to this newsgroup. I do not reply to personal e-mail
fredg - 15 Feb 2008 23:50 GMT >>> I am using the transfer spreadsheet command, but whenever the Excel >>> spreadsheet has spaces in the name, I don't know how to deal with that [quoted text clipped - 71 lines] > > Coby. Some time ago I had to import data from a spreadsheet. Some of the column names had trailing spaces in them, something like "MySheet ". The spaces were not chr(32). I don't remember now what the ascii was and I have no idea how they got there, but it created a problem form me. Perhaps the space in your worksheet name is not a chr(32) space as it would be in your access module code.
Try this. Open the workbook. Right-click on the worksheet name and select Rename. Copy the name to the clipboard using Ctrl + C. Open the Access module and paste the name into the code using Ctrl+V. Add the ! and the column and row numbers and place the entire Range text within double quotes (not single quotes). Does it work now? This is about all I can think of without actually seeing and experimenting with your spreadsheet.
 Signature Fred Please respond only to this newsgroup. I do not reply to personal e-mail
PatK - 16 Feb 2008 19:33 GMT This exact statement worked for me (note first is a link, second is an import):
DoCmd.TransferSpreadsheet acLink, , "Price 2008a", "C:\Documents and Settings\pklocke\My Documents\2.5 New Ticket Mgmt\Data\2008-01.xls", True, "Closed 200801!A1:B20"
Sorry for long file name...I did not want to tweek anything. Now, I am using Access 2007, but not sure if it would make a difference. Here is the import version:
DoCmd.TransferSpreadsheet acImport, , "Price 2008a", "C:\Documents and Settings\pklocke\My Documents\2.5 New Ticket Mgmt\Data\2008-01.xls", True, "Closed 200801!A1:B20"
Another anomoly, as I had been working on similar problem, but in my case, I did not want a range...I wanted the whole worksheet:
If you want the whole worksheet, regardless of range, it appears you must insert a bang (!) sign at the end of the worksheet name, like "Worksheet!"
I share that due to the fact it cost me two days work trying to figure out! Near as I can tell, it is not documented anywhere.
Patk
> >>> I am using the transfer spreadsheet command, but whenever the Excel > >>> spreadsheet has spaces in the name, I don't know how to deal with that [quoted text clipped - 90 lines] > This is about all I can think of without actually seeing and > experimenting with your spreadsheet. George Nicholson - 18 Feb 2008 18:24 GMT Haven't tested this recently but some notes in old code of mine say that if special characters are involved, the syntax would be: " 'My Sheet!' "
*The spaces between single and double quotes in the above are only for syntax clarity and should be removed (i.e, s/b "' and '").*
I'm sure that the !' sequence is the key reason for me leaving that note to myself, so maybe: "'Pricing 2008!'A2:U300"
If I remember correctly, using this syntax when there are no special characters in the name will cause an error (after all, why should anything like referencing an Excel sheet be simple?). I didn't think that spaces qualified as special characters, but since you are having problems, I thought I'd toss this out in case its of any help. (It might be that the worksheet has what *appears* to be a space, but is actually a special character in disguise, in which case this might do the trick).
 Signature HTH, George
On Feb 15, 2:12 pm, fredg <fgutk...@example.invalid> wrote:
> On Fri, 15 Feb 2008 11:54:00 -0800 (PST), Coby wrote: > > I am using the transfer spreadsheet command, but whenever the Excel [quoted text clipped - 41 lines] > > - Show quoted text - Thanks for the help, Fred!
The error I am getting is "Syntax error (missing operator0 in query expression 'Pricing 2008$A2:U300'. The message shows a $ in place of the ! that I actually used.
I am not sure if that means anything.
Also, I am not importing into an existing table. And, I am just going with the field names that are automatically assinged. I am using spreadsheet type 8
The strUsFile is the same in both instances: that is the directory path and file name.
The only reason I think it has to do with the spaces is because when I rename the worksheet name without spaces, then try it referring to the name without spaces. . . it works. Also, the problem only exists when I am dealing with spreadsheets with spaces in the names.
Perhaps, there is some other syntax that needs to be used ie, brackets, apostrophe, etc. that the worksheet object requires to refer to it whenever it has spaces.
I don't know . . . just thinking outloud to bounce that off of what you think.
Thanks,
Coby.
cfitzger - 09 May 2008 15:49 GMT Coby,
Did you ever resolve this issue? I am having the same problem and it is certainly related to the space. Remove the space in the worksheet name and it works. Leave the space and pull the whole sheet (ie, 'Sheet 1!') and it works. I just can't get it to pick a range within a sheet that has a space. Same errors you have including the strange replacement of the ! with a $.
Thanks
>> > I am using the transfer spreadsheet command, but whenever the Excel >> > spreadsheet has spaces in the name, I don't know how to deal with that [quoted text clipped - 32 lines] > >Coby.
|
|
|