PDA

View Full Version : Solved: Open workbook when excel starts



BENSON
02-19-2007, 12:47 AM
I found the following code in prevoius thread "Open workbook based on specific date" could the code be modified to open the workbook whenever excel is opened

MANY thanks



Option Explicit

Private Sub Workbook_Open()
ProcessFiles
End Sub

Sub ProcessFiles()
Dim MyPath As String, MyName As String
Dim Sheet As String, Address As String
Dim d As Long

MyPath = "C:\AAA\"
MyName = "TestDate.xls"

For d = 10 To 30
If GetData(MyPath, MyName, "Sheet1", "A" & d) = Date Then
Workbooks.Open (MyPath & MyName)
Exit For
End If
Next
End Sub

Private Function GetData(Path, File, Sheet, Address)
Dim Data As String
Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
Range(Address).Range("A1").Address(, , xlR1C1)
GetData = ExecuteExcel4Macro(Data)
End Function

Brandtrock
02-19-2007, 12:58 AM
One way to do this would be to specify that the file be opened at startup by excel. Under Tools>Options you can specify files to open at startup. See below.

Bob Phillips
02-19-2007, 02:12 AM
If you put that code in the Personal.xls file, it will always happen at Excel startup, as that file (any any others in the XLSTART directory) are opened as Excel starts.

BENSON
02-22-2007, 12:19 AM
MANY THANKS I HAD FORGOTTEN ABOUT THE MXL START UP FOLDER