PDA

View Full Version : Worksheet Open Problem



JaFF
05-11-2011, 01:53 PM
Hello VBA users,

I'm relatively new to VBA although I know basic programming. My ultimate goal is to open a workbook the name of which is specified in a cell in a sheet in the workbook that is already open. As I understand the code for that would be something like this:

Dim file As String
file = Sheets("History").Cells(2, 1)
Workbooks.Open Filename = "C:\" & file

However, this gives me a run-time error 1004. The error message box is not helpful at all: instead of a basic description I get a lot of "?" marks with "False.xlsx" between them (so it converted whatever characters there were into ? but left the False.xlsx and the punctuation marks untouched). I know that the file exists and the name is correct - I've manually created .xls and .xlsx files and tried to read those which resulted in the same error. I also know that the sheets I created were not protected.

I'm sorry I'm not being very helpful, but are there any common mistakes that can lead to this?

Thanks!

SoftwareMatt
05-12-2011, 02:04 AM
Could you just link the excel file to Access as a Linked table and then you would have an easy way to get to the other Excel path you need?
Then all you would need to do is open it.

JaFF
05-12-2011, 07:35 AM
Could you just link the excel file to Access as a Linked table and then you would have an easy way to get to the other Excel path you need?
Then all you would need to do is open it.
I'm not sure how that would work. Does this method require opening Access?

I think I'm not explaining the overall situation very well... I've been asked to create a excel-based program based on user forms to manage some data. It is assumed that the user only has excel. It does not matter if it's .xls or .xlsx. All files manipulated are of a set standard layout.

Could you please tell me more about your suggestion? As I've read it, I don't understand what you're suggesting I do because I'm very new to this.

Thank you very much! :)

SoftwareMatt
05-12-2011, 07:43 AM
Ahh, ok, I understand now - I mentioned Access because you posted in the Access forum. I must admit my knowledge of Excel is not as good as Access but could you not just use a hyperlink?

JaFF
05-12-2011, 11:43 AM
Ahh, ok, I understand now - I mentioned Access because you posted in the Access forum. I must admit my knowledge of Excel is not as good as Access but could you not just use a hyperlink?
A hyperlink? Sorry I'm not getting it; the file I want to open is on the computer already... Or is a hyperlink another way of opening such files?

orange
05-13-2011, 12:47 PM
It appears that this request has nothing to do with MS Access and may have just been posted in the wrong forum, is this correct?

JaFF
05-13-2011, 01:07 PM
It appears that this request has nothing to do with MS Access and may have just been posted in the wrong forum, is this correct?
Yes, apologies for that. The problem has since been fixed: it didn't like the variable name being "file" because it is a reserved word.