VBA Save

raccoon588

Board Regular
Joined
Aug 5, 2016
Messages
118
I have a file that saves everyday at 1am. It is locates on a network drive in a specific folder. I cant figure out why it saves to the drive and saves to the local PCs documents.

Code:
Sub sveWrkBk()
    Application.DisplayAlerts = False
    ActiveWorkbook.Save
    Application.OnTime TimeValue("01:00:00"), "sveWrkBk"
    Application.DisplayAlerts = True
End Sub
 
Last edited by a moderator:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
It's saving to documents as you aren't declaring a location. You'll need to change Save to SaveAs

You can manually enter the file name and location, or use this method to keep the current location and name.

Code:
[TABLE="width: 615"]
<tbody>[TR]
[TD]Dim workbook_Name As Variant[/TD]
[/TR]
[TR]
[TD]workbook_Name = Application.GetSaveAsFilename[/TD]
[/TR]
[TR]
[TD]If workbook_Name <> False Then[/TD]
[/TR]
[TR]
[TD]ActiveWorkbook.SaveAs Filename:=workbook_Name[/TD]
[/TR]
[TR]
[TD]End If[/TD]
[/TR]
</tbody>[/TABLE]

https://powerspreadsheets.com/vba-save-workbook/
 
Last edited:
Upvote 0
I would try a different method, only as I don't quite follow the logic applied here. (The code supplied also asks for the location first which I failed to realize.) So you want to replace this:

Code:
[COLOR=#333333]ActiveWorkbook.Save[/COLOR]

With:

Code:
workbook_Name = ActiveWorkbook.FullName
ActiveWorkbook.SaveAs Filename:=workbook_Name


Personally i'd enter this in "ThisWorkbook", so the macro doesn't need to be triggered.

Code:
Private Sub Workbook_Open()


Application.OnTime TimeValue("01:00:00"), "sveWrkBk"


End Sub

Then in a module:

Code:
Sub sveWrkBk()


Dim workbook_Name As Variant


    Application.DisplayAlerts = False
    workbook_Name = ActiveWorkbook.FullName
    ActiveWorkbook.SaveAs Filename:=workbook_Name
    Application.DisplayAlerts = True


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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