Need help - Naming the file path instead of using thisworrkbook.path. Thanks for helping!

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Sorry I have to restart part of my old thread.
Could someone please edit this part or the whole code..
Code:
MyFile = [COLOR=red]ThisWorkbook.Path & "\Book2.xls"[/COLOR]
I want myself to enter the whole path myself like 'C\Macro and Excels trix\.. etc and not "thisworkbook.path & \book2.xls"

Thanks pedie;)

Code:
Sub Test2()

    Dim wb As Workbook, MyFile As String
    
    MyFile = [COLOR=red]ThisWorkbook.Path & "\Book2.xls"[/COLOR]
    On Error Resume Next
        Set wb = Workbooks.Open(Filename:=MyFile)
    On Error GoTo 0
    
    If wb Is Nothing Then MsgBox "Couldn't locate " & MyFile: Exit Sub
    
    With wb
        '.Activate
        '.Cells.Activate
        With ActiveSheet
            .Range("A1").Value = "Hello!"
            .Range("A3").Formula = "=A1"
        End With
        .Save
        .Close
    End With
    
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi, VoG, Hi Lenze!!!

Thanks for quick reply, but I dont want to enter file path everytime i run the code. I want to predefine the path in the code itself;)

Thanks Pedie
 
Upvote 0
Vog...you're GREAT...lemmi try this out.
Please gimi a moment

Pedie:):p
 
Upvote 0
VoG!
Just one more thing. Can I make the code triger and click on "read only" button..it pops up for me to click on read only...i dont know why....:confused:

Pedie
 
Upvote 0
Perhaps

Code:
    On Error Resume Next
    Application.DisplayAlerts = False
        Set wb = Workbooks.Open(Filename:=MyFile)
    Application.DisplayAlerts = True
    On Error GoTo 0
 
Upvote 0
VoG!,
I am not sure why but it still does not triger read only..it always pop up and does not cont unless i click on Read Only or hit Enter!:p

Could you please see why I am getting this?
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,938
Members
448,534
Latest member
benefuexx

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