save over the original .xls file VBA

Lenna

Active Member
Joined
Jun 25, 2014
Messages
269
Hello,

I've been using the following code to save over the original notepad file after it has been modified in excel. I would like to do the same with .xls file. How do I change this code to suit my needs?

Thanks,

Lenna

Code:
Dim myPath As String
'   original filename & path
    myPath = Application.ActiveWorkbook.FullName
    
'   Selects & copies trimmed data range, _
    assuming starts in A1 with no blank rows b4 last row
    Range("A:E").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
'   Turns off error prompt window b4 closing temp excel worksheet _
    (to allow Notepad to save revisions over original filename) _
    then reactivates error prompt window
    Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Application.DisplayAlerts = True
'   Reopens original unmodified files in notepad from same original filename & path _
    then selects all to paste modified version over it, resaves it with original filename & path _
    & closes it via Alt + F4
    Shell "notepad.exe """ & myPath & """", vbNormalFocus
    SendKeys "^a"
    SendKeys "^v"
    SendKeys "^s"
    SendKeys "%{f4}"
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,191,183
Messages
5,985,172
Members
439,944
Latest member
Vangelis74

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