Open an Opened Excel File

balvy

New Member
Joined
Nov 14, 2013
Messages
11
Hello, I have an Excel File where i have all my projects and a button so when i need to open a project i just click on the button to open it. but the problem is that when i already have that file open and i click on it again it doesn't let me open it without erasing the data i had worked on.
this is the code i'm using:
Code:
Sub cronosall()
Workbooks.Open ("C:\Users\Admin\Documents\Work\Cronos")
End Sub

What i need is when i click on "cronosall" or one of the many projects even if it's open to have the window pop up.
or that whenever i click on the "cronosall" to save the opened file so i it doesn't erase the data i was working on.

Thanks for all your help
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Maybe something like this...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit
[/COLOR]
[COLOR=darkblue]Sub[/COLOR] cronosall()

    [COLOR=darkblue]Dim[/COLOR] wsOpen              [COLOR=darkblue]As[/COLOR] Worksheet
    [COLOR=darkblue]Dim[/COLOR] sPath               [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] sFile               [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    
    sPath = "C:\Users\Admin\Documents\Work\"
    [COLOR=darkblue]If[/COLOR] Right(sPath, 1) <> "\" [COLOR=darkblue]Then[/COLOR] sPath = sPath & "\"
    
    sFile = "Cronos.xlsm"
    
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
    [COLOR=darkblue]Set[/COLOR] wsOpen = Workbooks(sFile)
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
    [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] wsOpen [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
        wsOpen.Activate
    [COLOR=darkblue]Else[/COLOR]
        [COLOR=darkblue]If[/COLOR] Len(Dir(sPath & sFile, vbNormal)) = 0 [COLOR=darkblue]Then[/COLOR]
            MsgBox "File not found!", vbExclamation
        [COLOR=darkblue]Else[/COLOR]
            [COLOR=darkblue]Set[/COLOR] wsOpen = Workbooks.Open(sPath & sFile)
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 
Upvote 0
Maybe something like this...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit
[/COLOR]
[COLOR=darkblue]Sub[/COLOR] cronosall()

    [COLOR=darkblue]Dim[/COLOR] wsOpen              [COLOR=darkblue]As[/COLOR] Worksheet
    [COLOR=darkblue]Dim[/COLOR] sPath               [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] sFile               [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    
    sPath = "C:\Users\Admin\Documents\Work\"
    [COLOR=darkblue]If[/COLOR] Right(sPath, 1) <> "\" [COLOR=darkblue]Then[/COLOR] sPath = sPath & "\"
    
    sFile = "Cronos.xlsm"
    
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
    [COLOR=darkblue]Set[/COLOR] wsOpen = Workbooks(sFile)
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
    [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] wsOpen [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
        wsOpen.Activate
    [COLOR=darkblue]Else[/COLOR]
        [COLOR=darkblue]If[/COLOR] Len(Dir(sPath & sFile, vbNormal)) = 0 [COLOR=darkblue]Then[/COLOR]
            MsgBox "File not found!", vbExclamation
        [COLOR=darkblue]Else[/COLOR]
            [COLOR=darkblue]Set[/COLOR] wsOpen = Workbooks.Open(sPath & sFile)
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!

thanks for your help.

It kinda works. it still does the same as the first one i had. when i click on the button of a file that's already opened i get the pop up that says it cant be opened without erasing that data.

i would send a screen shot but its in spanish.
 
Upvote 0
Sorry, my mistake. Try the following instead...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit
[/COLOR]
[COLOR=darkblue]Sub[/COLOR] cronosall()

    [COLOR=darkblue]Dim[/COLOR] wbOpen              [COLOR=darkblue]As[/COLOR] Workbook
    [COLOR=darkblue]Dim[/COLOR] sPath               [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] sFile               [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    
    sPath = "C:\Users\Admin\Documents\Work\"
    [COLOR=darkblue]If[/COLOR] Right(sPath, 1) <> "\" [COLOR=darkblue]Then[/COLOR] sPath = sPath & "\"
    
    sFile = "Cronos.xlsm"
    
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
    [COLOR=darkblue]Set[/COLOR] wbOpen = Workbooks(sFile)
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
    [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] wbOpen [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
        wbOpen.Activate
    [COLOR=darkblue]Else[/COLOR]
        [COLOR=darkblue]If[/COLOR] Len(Dir(sPath & sFile, vbNormal)) = 0 [COLOR=darkblue]Then[/COLOR]
            MsgBox "File not found!", vbExclamation
        [COLOR=darkblue]Else[/COLOR]
            [COLOR=darkblue]Set[/COLOR] wbOpen = Workbooks.Open(sPath & sFile)
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,695
Messages
6,126,261
Members
449,307
Latest member
Andile

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top