ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA to open a shortcut to a workbook (https://www.excelbanter.com/excel-programming/398826-vba-open-shortcut-workbook.html)

Walden2

VBA to open a shortcut to a workbook
 
Is there a way to use VBA to "open" shortcuts to workbooks?

For example,
Book1.xls is in Folder A
There is a "shortcut" to Book1.xls in Folder B
Book2.xls is a workbook in Folder B
When opening Book2.xls, what VBA would look for shortcuts in the
Folder B and open those files?

Thanks,
Walden


Bob Phillips

VBA to open a shortcut to a workbook
 
Sub LoopFolders()
Dim oFSO As Object
Dim Folder As Object
Dim Files As Object
Dim file As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set Folder = oFSO.GetFolder("c:\Test")

For Each file In Folder.Files
If file.Type Like "*Shortcut*" Then
Workbooks.Open Filename:=file.Path
End If
Next file

Set oFSO = Nothing

End Sub



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Walden2" wrote in message
s.com...
Is there a way to use VBA to "open" shortcuts to workbooks?

For example,
Book1.xls is in Folder A
There is a "shortcut" to Book1.xls in Folder B
Book2.xls is a workbook in Folder B
When opening Book2.xls, what VBA would look for shortcuts in the
Folder B and open those files?

Thanks,
Walden




Jim May

VBA to open a shortcut to a workbook
 
All you will need to do is in Book2.xls
Alt-F11 and in the ThisWorkbook Code Window paste in:

Private Sub Workbook_Open()
LoopFolders ' Bob's code posted in a Standard module (assumed)
End Sub

Jim May



"Walden2" wrote:

Is there a way to use VBA to "open" shortcuts to workbooks?

For example,
Book1.xls is in Folder A
There is a "shortcut" to Book1.xls in Folder B
Book2.xls is a workbook in Folder B
When opening Book2.xls, what VBA would look for shortcuts in the
Folder B and open those files?

Thanks,
Walden



Walden2

VBA to open a shortcut to a workbook
 
This worked great. Thanks much.

Walden

On Oct 6, 7:48 am, "Bob Phillips" wrote:
Sub LoopFolders()
Dim oFSO As Object
Dim Folder As Object
Dim Files As Object
Dim file As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set Folder = oFSO.GetFolder("c:\Test")

For Each file In Folder.Files
If file.Type Like "*Shortcut*" Then
Workbooks.Open Filename:=file.Path
End If
Next file

Set oFSO = Nothing

End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Walden2" wrote in message

s.com...



Is there a way to use VBA to "open" shortcuts to workbooks?


For example,
Book1.xls is in Folder A
There is a "shortcut" to Book1.xls in Folder B
Book2.xls is a workbook in Folder B
When opening Book2.xls, what VBA would look for shortcuts in the
Folder B and open those files?


Thanks,
Walden- Hide quoted text -


- Show quoted text -





All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com