Autosave Code Problem

excellearnerz

New Member
Joined
May 5, 2020
Messages
17
Office Version
  1. 365
  2. 2016
  3. 2011
  4. 2010
Platform
  1. Windows
Good day,

I scrounged up a code I dont fully understand, but it seems to work. The goal of the code is that when there are any changes in the cell range I defined, the spreadsheet will autosave/export as a pdf file. However, I want that when another set of changes are submitted to the spreadsheet, it will save again with a sequential file name, and not overwrite the old save.

Here is the code:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Step 1: Does the changed range intersect?
If Intersect(Target, Range("A1:AT55")) Is Nothing Then
'Step 2: If there is no intersection, exit procedure
Exit Sub
'Step 3: If there is an intersection, save the workbook
Else
Sheet4.ExportAsFixedFormat xlTypePDF, "C:\Users\Office-PC\Desktop\Destiny\INRToday.pdf"
'Step 4: Close out the If statement
End If
End Sub
File-Copy-icon.png




Any help will be greatly appreciated.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If you make your file name contain date and time 202005051723 it will always be a new name yyyyymmddhhmm
 
Upvote 0
Sir,

I have no knowledge on how to begin doing that. If you can provide a code, I will be forever grateful
 
Upvote 0
Sir,

I have no knowledge on how to begin doing that. If you can provide a code, I will be forever grateful
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim serial As String
'Step 1: Does the changed range intersect?
If Intersect(Target, Range("A1:AT55")) Is Nothing Then
'Step 2: If there is no intersection, exit procedure
Exit Sub
'Step 3: If there is an intersection, save the workbook
Else
serial = Now()
serial = Format(serial, "yyyymmddhhmm")
Sheet4.ExportAsFixedFormat xlTypePDF, "C:\Users\Office-PC\Desktop\Destiny\INRToday" & serial & ".pdf"
'Step 4: Close out the If statement
End If
End Sub

Sub test()
Dim serial As String
serial = Now()
serial = Format(serial, "yyyymmddhhmm")
End Sub
 
Upvote 0
Hello Sir,

I tried out your code, now it is not saving at all in the directory. What could have happened here?

The intersected range values "change" due to links from another spreadsheet, this other spreadsheet is where I input the raw data. Does it count as change to the spreadsheet with the macro? I also have an IF function on the spreadsheet, it should count as change right?
 
Upvote 0
mole,

Any reason why you did this over two lines:
VBA Code:
serial = Now()
serial = Format(serial, "yyyymmddhhmm")
instead of one, like this?
VBA Code:
serial = Format(Now(), "yyyymmddhhmm")
 
Upvote 0
mole,

Any reason why you did this over two lines:
VBA Code:
serial = Now()
serial = Format(serial, "yyyymmddhhmm")
instead of one, like this?
VBA Code:
serial = Format(Now(), "yyyymmddhhmm")
because when someone is learning it can help people to understand the steps involved, it is not my trade, as is evident most of the time
 
Upvote 0
Hello Sir,

I tried out your code, now it is not saving at all in the directory. What could have happened here?

The intersected range values "change" due to links from another spreadsheet, this other spreadsheet is where I input the raw data. Does it count as change to the spreadsheet with the macro? I also have an IF function on the spreadsheet, it should count as change right?
if you drop those minor changes does it go back to saving correctly
 
Upvote 0
because when someone is learning it can help people to understand the steps involved, it is not my trade, as is evident most of the time
Gotcha, I often break them up into steps to, so it is easier for them to see what is going on.
 
Upvote 0
if you drop those minor changes does it go back to saving correctly
Sorry sir, it seems your code is working perfectly, i tried manually changing cells within the range and I now have multiple files as proof. Now the problem is the linked data, and the IF function within the range is not registering as a change event. This is the final piece for my program to work as I intended, please Sir, help me push through.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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