open a new applicaiton

woonyah
06-18-2008, 09:16 PM
Hi.

For the previous post on auto_open, thanks for your help. It helps me alot.

Now i got something to ask you again.

I have this code


Private Sub Workbook_open()
Application.Visible = True
If Application.Workbooks.Count > 1 Then
With CreateObject("Excel.Application")
.Visible = True
.DisplayAlerts = False
.Workbooks.Open ThisWorkbook.FullName, , True
.ActiveWorkbook.RunAutoMacros xlAutoOpen
End With
ThisWorkbook.Close False
End If

If ActiveWorkbook.Name = "Portfolio_123.xls" Then
DisableCutAndPaste
Else:
Call EnableCutAndPaste
End If
End Sub



However, when i open the file with this code and together with 3 other files that are also being opened before hand, it is a read only file. How can improve in the code to make it not a read only file?

NEOLLE
06-18-2008, 09:31 PM
Do you mean that (only) the fourth file is read-only? Have you checked the file attribute? Perhaps the file was set to read-only.
:)

woonyah
06-18-2008, 11:46 PM
No the file is not set as read-only. Yes, only the fourth file is read-only. I was thinking if it is because of the code.


Application.Visible = True
If Application.Workbooks.Count > 1 Then
With CreateObject("Excel.Application")
.Visible = True
.DisplayAlerts = False
.Workbooks.Open ThisWorkbook.FullName, , True
.ActiveWorkbook.RunAutoMacros xlAutoOpen
End With
ThisWorkbook.Close False
End If


The code will open a new application for the fourth file. And the code state that

If Application.Workbooks.Count > 1 Then
With CreateObject("Excel.Application")


So with one application on hand, and the second application (for the fourth file), the fourth file is a read-only file. Hence how should i imporve on the syntax and make it not a read-only file?

Please guide me. Thanks!

Colin Legg
06-19-2008, 01:32 AM
Hi Woonyah

Related thread:
http://www.xtremevbtalk.com/showthread.php?t=297576

Because you already have the workbook open with read-write permission, it's "locked" for editing.

You will have to change the fileaccess of the open workbook to read-only before you attempt to open it in the new instance. You can't do this using the workbook object's readonly property because that property is itself read-only, but you can achieve this with the workbook object's ChangeFileAccess method - check it out in your Excel VBA helpfile.

By the way, if you don't want the Workbook_Open() procedure to fire in the new instance you can toggle that application object's enableevents property to false before you open the workbook in it.

Colin

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum