Consulting

Results 1 to 8 of 8

Thread: New Excel Application

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Posts
    22
    Location

    New Excel Application

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2008
    Posts
    22
    Location
    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?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Jun 2008
    Posts
    22
    Location
    So how can i control from window? I cant run code to force it to open?

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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

    [vba]

    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
    [/vba]
    Last edited by Bob Phillips; 06-17-2008 at 11:45 PM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    Jun 2008
    Posts
    22
    Location
    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?
    Last edited by bear; 06-17-2008 at 08:13 PM.

  8. #8
    VBAX Regular
    Joined
    Jun 2008
    Posts
    22
    Location
    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!
    Last edited by bear; 06-18-2008 at 11:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •