Opening an Excel workbook with VBA from Access

B

Bill

I've experimented with the workbook.open method in VBA, but seem to be
getting better results with the following code. I can't see that there is a
setting with the code below that can be used to prevent the user from
receiving a notification later when the Excel file is no longer read only
and has been unlocked for editing. This can be done of course in the
workbook open method.

I would appreciate hearing whether this can be done in the code below.

Bill
____________________________________
Dim xlApp As Excel.Workbook
Dim xlWindow As Excel.Window

'Check to see if the file name passed in to
'the procedure is valid
If Dir(Path) = "" Then
MsgBox "'" & Path & "' isn't a valid path!"
Exit Sub
Else
Set xlApp = GetObject(Path)

'Show the Excel Application Window
xlApp.Parent.Visible = True

'Unhide each window in the WorkBook
For Each xlWindow In xlApp.Windows
xlWindow.Visible = True
Next

'Prevent Excel from prompting to save changes
'to the workbook when the user exits
xlApp.Saved = True

End If
 
J

Jim Cone

Not that I know of, however, this should work...
'--
Sub StartFresh()
Dim xlApp As Excel.Application
Dim WB As Excel.Workbook
Dim WS As Excel.Worksheet
Dim strPath As String

strPath = "C:\Documents and Settings\MyGirlFriends.xls"
Set xlApp = New Excel.Application
Set WB = xlApp.Workbooks.Open(strPath, , , , , , , , , , False)
Set WS = WB.Sheets(1)
xlApp.Visible = True

'do stuff

Set WS = Nothing
WB.Close True ' or False
Set WB = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub
--
Jim Cone
Portland, Oregon USA


"Bill" <[email protected]>
wrote in message
I've experimented with the workbook.open method in VBA, but seem to be
getting better results with the following code. I can't see that there is a
setting with the code below that can be used to prevent the user from
receiving a notification later when the Excel file is no longer read only
and has been unlocked for editing. This can be done of course in the
workbook open method.
I would appreciate hearing whether this can be done in the code below.
Bill
____________________________________
Dim xlApp As Excel.Workbook
Dim xlWindow As Excel.Window

'Check to see if the file name passed in to
'the procedure is valid
If Dir(Path) = "" Then
MsgBox "'" & Path & "' isn't a valid path!"
Exit Sub
Else
Set xlApp = GetObject(Path)
'Show the Excel Application Window
xlApp.Parent.Visible = True
'Unhide each window in the WorkBook
For Each xlWindow In xlApp.Windows
xlWindow.Visible = True
Next
'Prevent Excel from prompting to save changes
'to the workbook when the user exits
xlApp.Saved = True
End If
 

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