Workbook.open failure

M

MattJ

I have a slight issue when trying to run a macro with the workbook.open
command.
The problem is that I cannot open an excel file without going throught he
whole filepath usin file/open in excel.

Is there anyway in which I can just open a file without having to "show"
excel the exact file path everytime i wish to open a certain workbook?

Many thanks in advance
Matt
 
B

Bob Greenblatt

I have a slight issue when trying to run a macro with the workbook.open
command.
The problem is that I cannot open an excel file without going throught he
whole filepath usin file/open in excel.

Is there anyway in which I can just open a file without having to "show"
excel the exact file path everytime i wish to open a certain workbook?

Many thanks in advance
Matt
Excel has a default directory. It is usually the directory from which the
first file opened belongs. It is always a good idea to specify the full path
name to a file. If your macro statement says workbooks.open filename:=...,
specify the full path here and excel will not present a dialog.
 
J

JE McGimpsey

MattJ said:
I have a slight issue when trying to run a macro with the workbook.open
command.
The problem is that I cannot open an excel file without going throught he
whole filepath usin file/open in excel.

Is there anyway in which I can just open a file without having to "show"
excel the exact file path everytime i wish to open a certain workbook?

First, I assume you mean the Workbooks.Open method.

XL has to know what path to tell MacOS to look in for the file.

If you don't specify a path, it looks in the path stored in the
Application.CurDir property. You can change this folder using the ChDir
statment, but that then requires you to specify the entire path (though
you can move relative to the current directory using ChDir "..", or by
specifying a folder in the current folder).

You can also use the folder your workbook is in as a reference. For
instance if the file you want to open, say "Test.xls", is in the same
folder as the workbook running the Workbooks.Open command, you can use
something like

Dim sFullPath As String
sFullPath = ThisWorkbook.Path & Application.PathSeparator & "Test.xls"
Workbooks.Open sFullPath
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top