Open File Automatically

michaelp1029

Board Regular
Joined
Jul 15, 2008
Messages
63
So here's what i want to do. I want to press a button so that it automatically opens up the file "NYSEG-RG&E-NGrid Profile Pricing Automated.xls" from the "N:\Group\Gateway\McCarthy's Sausage Factory" folder. Here's what I got and it ain't working. Help?

Sub FindPrices()
Dim wbResults As Workbook

With Application.FileSearch
.NewSearch
.LookIn = "N:\Group\Gateway\McCarthy's Sausage Factory"
.FileType = msoFileTypeExcelWorkbooks
.Filename = "NYSEG-RG&E-NGrid Profile Pricing Automated.xls"
If .Execute > 0 Then 'Workbooks in folder
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Else
MsgBox "File Does Not Exist"
End If
End With
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

nirvana_

Board Regular
Joined
Mar 25, 2009
Messages
141
Try this code. User Ctrl+K to open the file automatically.

Code:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+k
'
    Workbooks.Open Filename:="N:\Group\Gateway\McCarthy's Sausage Factory\NYSEG-RG&E-NGrid Profile Pricing Automated.xls"
End Sub
 
Upvote 0

rconverse

Well-known Member
Joined
Nov 29, 2007
Messages
1,187
Try this code. User Ctrl+K to open the file automatically.

Code:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+k
'
    Workbooks.Open Filename:="N:\Group\Gateway\McCarthy's Sausage Factory\NYSEG-RG&E-NGrid Profile Pricing Automated.xls"
End Sub

If you just copy and paste, how will Excel know the shortcut key?
 
Upvote 0

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
If you just copy and paste, how will Excel know the shortcut key?

You have to go in and instantiate the shortcut manually.

Also note that opening the workbook should be easily recordable, unless your path changes...

HTH,
 
Upvote 0

Forum statistics

Threads
1,191,718
Messages
5,988,271
Members
440,146
Latest member
rgomes8

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top