Open Workbook on new instance

0 votes

Would my code, which I'm currently working on, open workbooks in a new instance? How can I tell whether the workbook is opening in a new instance if it is opening the workbook?

Sub AQUAS()
 Dim bookPath As String, bookWb As Workbook
 bookPath = "\\C:\FLUXO CAIXA HINDY - 118.xlsm"
 Dim Resultado As VbMsgBoxResult
 Dim NewExcel As Object
 Set NewExcel = New Excel.Application
 
 With NewExcel
 
 If Dir(bookPath) = "" Then MsgBox "Planilha não encontrada": Exit Sub
 
 If IsWorkBookOpen(bookPath) Then
        Resultado = MsgBox("Arquivo em Uso, Abrir somente leitura?", vbYesNo + vbInformation, "AQUAS")
        If Resultado = vbYes Then
            Workbooks.Open (bookPath), True, True
            Application.WindowState = xlMaximized
        Else
            Exit Sub
        End If
 Else
        Workbooks.Open (bookPath), True
        Application.WindowState = xlMaximized
 End If
 
 End With
 
End Sub
Mar 23, 2023 in Others by Kithuzzz
• 38,010 points
279 views

1 answer to this question.

0 votes

It must function.

You aren't opening the Workbook in the newly generated instance, though. The With-clause instructs VBA to utilise the object for all members that are preceded by a dot, in your case the new Excel Instance. Thus, to access the Workbook in the just-created instance, use

With NewExcel
    If Dir(bookPath) = "" Then 
        MsgBox "Planilha não encontrada"
        Exit Sub
    End If

    If IsWorkBookOpen(bookPath) Then
        Resultado = MsgBox("Arquivo em Uso, Abrir somente leitura?", vbYesNo + vbInformation, "AQUAS")
        If Resultado <> vbYes Then Exit Sub
      
       .Workbooks.Open bookPath, True, True
    Else
       .Workbooks.Open bookPath, True
    End If
    .Application.WindowState = xlMaximized
 End With

Be careful, your code will not be able to close that Excel instance.

answered Mar 23, 2023 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
0 answers

How to open a new tab or a new window while writing an exam in AI - Onlime Remote Proctored

How to open a new tab or ...READ MORE

Jul 20, 2020 in Others by vimalkamal
• 120 points
3,287 views
0 votes
1 answer

Open Instagram user profile on android

To open instagram app- String scheme = "http://instagram.com/_u/USER"; String path ...READ MORE

answered May 31, 2022 in Others by nisha
• 2,210 points
1,477 views
0 votes
0 answers

Is it possible to open developer tools console in Chrome on Android phone?

Is it possible to open JS console ...READ MORE

Jun 14, 2022 in Others by nisha
• 2,210 points
1,216 views
–1 vote
1 answer

Open file in SDCard on Android

To open a file that is on ...READ MORE

answered Jun 20, 2022 in Others by nisha
• 2,210 points
39,529 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
876 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,183 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
481 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,670 points
731 views
0 votes
1 answer

Detect whether Excel workbook is already open

Try this: Option Explicit Sub Sample() ...READ MORE

answered Oct 31, 2022 in Others by narikkadan
• 63,420 points
303 views
0 votes
1 answer

How can I store the data of an open excel workbook in a collection using BluePrism?

To do what you want is like ...READ MORE

answered Nov 24, 2022 in Others by narikkadan
• 63,420 points
870 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP