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
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,953
Application.GetSaveAsFileName allows the user to fully specify the path and name.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Like this?

Code:
MyFile = InputBox("Enter full path and filename")
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
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
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650

ADVERTISEMENT

Try like this

Code:
MyFile = "C:\Test\Mybook.xls"
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Vog...you're GREAT...lemmi try this out.
Please gimi a moment

Pedie:):p
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875

ADVERTISEMENT

That is Perfect. Vog, thank you so much again for helping!

Pedie:)
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
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
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Perhaps

Code:
    On Error Resume Next
    Application.DisplayAlerts = False
        Set wb = Workbooks.Open(Filename:=MyFile)
    Application.DisplayAlerts = True
    On Error GoTo 0
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,205
Messages
5,623,361
Members
415,969
Latest member
Rey99

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
Top