Solved

Autosave Macro

Posted on 2012-12-21
6
165 Views
Last Modified: 2013-01-01
EE Professionals,

I'm looking for a little help on building out a small macro that autosaves a range to a desktop or file.  I have a WB/WS now that collects about 180 statements in 12 different sections that each have a range name.  What I am looking for is a macro that can be turned off and on (call it Auto-Save +),  that when a certain section is completed the macro will fire, save the range to a XLS WB with the name of the Range and outputted to a folder on the desktop.

Anyone seen something like that before?

Thanks in advance,

B.
0
Comment
Question by:Bright01
  • 4
  • 2
6 Comments
 
LVL 6

Expert Comment

by:scifo_dk
Comment Utility
Hi,

Give it at go with this, and modify accordingly:

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If (Target.Address = "$A$1") Then
         
        Dim wbI As Workbook, wbO As Workbook
        Dim wsI As Worksheet, wsO As Worksheet
    
        ' Source/Input Workbook
        Set wbI = ThisWorkbook
        ' Set the relevant sheet from where you want to copy
        Set wsI = wbI.Sheets("Sheet1")
    
        ' Destination/Output Workbook
        Set wbO = Workbooks.Add
    
        With wbO
            ' Set the relevant sheet to where you want to paste
            Set wsO = wbO.Sheets("Sheet1")
    
            ' Save the file
            .SaveAs Filename:="C:\Book2.xls", FileFormat:=56
    
            ' Copy the range
            wsI.Range("A1:B10").Copy
    
            ' Paste it in say Cell A1. Change as applicable
            wsO.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        End With
        
        Application.EnableEvents = True
    End Sub

Open in new window


Sources:
Trigger on change
Copy range to new workbook
0
 

Author Comment

by:Bright01
Comment Utility
Scifo,

Thank you for the code.  Several key questions;

1.) Do I put this in a module, This Workbook or the Sheet that it is monitoring?  I think I put this in the sheet.
2.) Is the Target Address the trigger?  
3.) Do I put the trigger in for each copy range?   wsI.Range("A1:B10").Copy

The way I have this set up is that I have 180 statements in 12 Sections.  I'm thinking that I identify the first statement in a category and that drives the firing of the macro.  I'm thinking that as it saves, it just saves all completed sections so it's not creating new WBs on the desktop.

Am I thinking about this right?

Thank you,

B.
0
 
LVL 6

Accepted Solution

by:
scifo_dk earned 500 total points
Comment Utility
Edited: 15:08 - Found a bug in the code.
---------------------------------------------------------------

1. You should put this in the Sheet.

2. Yes it is.

3. I've updated the code, to use a range insted:

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Not Application.Intersect(Target, Range("A1:B10")) Is Nothing Then
         
        Dim wbI As Workbook, wbO As Workbook
        Dim wsI As Worksheet, wsO As Worksheet
    
        ' Source/Input Workbook
        Set wbI = ThisWorkbook
        ' Set the relevant sheet from where you want to copy
        Set wsI = wbI.Sheets("Sheet1")
    
        ' Destination/Output Workbook
        Set wbO = Workbooks.Add
    
        With wbO
            ' Set the relevant sheet to where you want to paste
            Set wsO = wbO.Sheets("Sheet1")
    
            ' Save the file
            .SaveAs Filename:="NewDoc.xls"
            ' Copy the range
            wsI.Range("A1:B10").Copy
    
            ' Paste it in say Cell A1. Change as applicable
            wsO.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        End With
         
    End If
         
        Application.EnableEvents = True
    End Sub

Open in new window


I am a bit unsure about what you mean with the last part of your comment?

The code copies the range "A1:B10" to a new sheet and saves it as "c:\NewBook.xlsx" if something has been changed in cells "A1:B10".
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Bright01
Comment Utility
Here's what I've got.

1.) I see NewDoc.xls, not NewBook.xlsx; is that right?
2.) I installed the code and tested it.   Here's the challenge, I need to have the macro fire when specific cells are changed (e.g. C3, C19, C33, C46).  When the Macro fires, it needs to copy over the existing Workbook (no need to ask about 'are you sure.....').
3.) It's not storing the WB on the desktop.

Finally, is there a way to activate and de-activate the macro (i.e. I'd like to assign a button on the WS to turn on/off Auto Backup).

Much thanks,

B.
0
 

Author Comment

by:Bright01
Comment Utility
Scifo,

Do you need anything from me on this?  I appreciate your help.

B.
0
 

Author Closing Comment

by:Bright01
Comment Utility
This solution did not work properly.  Last post was the 11 days ago.  I'm going to have to reissue the question with a clearer set of directions.

Thank you,

B.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now