Universal open

  • Thread starter Thread starter Geri
  • Start date Start date
G

Geri

Inside a folder, I have several workbooks that are linked. I have
recorded a macro to open them in sequence and it works fine, but I
does not work if I move the whole folder.

The code I use is -
Workbooks.Open Filename:= _
"xxx:xxx.xls"

How can I fix this? Is there a solution that will travel with the
location of the folder?
 
If the files are in the same folder as the workbook with the macro then you
could try:

'*****************************
Dim sFold
sFold = ThisWorkbook.Path

Workbooks.Open Filename:= sFold & ":xxx.xls"
'*****************************

Tim
 
Is your macro in the same folder as the other workbooks ?
If yes,
you cld use something like this.
Workbooks.Open (ThisWorkbook.Path & "\" & "xxx.xls")

If No,
You need to provide a way for the macro to knw where the files are stored.
Mulitple ways to do this. Try the foll below.

Sub FolderPath()
Dim FolderDestn As String
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
FolderDestn = .SelectedItems(1)
Else
FolderDestn = vbNullString
End If
End With
Workbooks.Open (FolderDestn & "\" & "xxx.xls")

End Sub

HTH,
 

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

Back
Top