PDA

View Full Version : New Excel Application



bear
06-17-2008, 02:18 AM
Hi,

My problem is that i want to open my file in a new excel application/window. The following is the code i am using:

Sub ExcelInstances()
Dim xlApp1 As Object
Set xlApp1 = CreateObject("Excel.Application")
xlApp1.Visible = True
xlApp1.Workbooks.Open filename:="U:\Disable control wip\test\test_123.xls"
End Sub

When i run this code in VBA it can work. But when i open my file in my folder, i this code dont seems to run. What code can i use if i want to open the file in a new window.

Bear

Bob Phillips
06-17-2008, 02:23 AM
I don't understand what you mean by ...

When i run this code in VBA it can work. But when i open my file in my folder, i this code dont seems to run.

bear
06-17-2008, 02:47 AM
Okay, it means that..

Orginally, i have already open 3 excel files. And now i need to open the file 123 in a new excel application. So when i add the code into excel vba and run the code, a new excel application appear. But when i am close and open the file at folder level, file 123 doesnt appear to be in a new excel application. It is in under the same application as the 3 files that are opened.

Is it better now?

Bob Phillips
06-17-2008, 02:57 AM
I think so, but that is just how it works.

When you control it from another workbook, you can control how it opens, when you do it from windows, windows controls it.

bear
06-17-2008, 03:02 AM
So how can i control from window? I cant run code to force it to open?

Bob Phillips
06-17-2008, 03:30 AM
Well you could try adding this Workbook_Open to the 123 workbook code, but don't blame me if it creates havoc, it is truly horrible IMO



Private Sub Workbook_Open()

Application.Visible = True ' for testing

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

End Sub

bear
06-17-2008, 05:53 PM
Thanks a lot. =)

Btw, the code you give me, the file is read-only. So is it possible not to make it as a read only file?

bear
06-18-2008, 05:51 PM
Please help me!
Is there a way to make the file not an read only file?
The code you gave me useful, but it is only in a read only format...

Wish to hear from your reply soon!