Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Create new excel files, Save backup of excel file

Hello,

I have 2 questions:

I have an excel worksheet with 4 sections. I get my data from 4 users.
I created 4 files (one file for user). Each file contains user's
section.
My problem is that I update my worksheet frequently and I want to
automate the creation of users files. How can I do it using VBA ?

I want to backup my excel file (and all the files within its directory)
to a new folder.
How can I do this using VBA ?

Thank you
Gil D.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Create new excel files, Save backup of excel file

I want to backup my excel file (and all the files within its directory)
to a new folder.
How can I do this using VBA ?


Function BackUp(srcFolder As String, DestFolder As String, createFolder
As Boolean)
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(srcFolder)
Set objFiles = objFolder.Files

If createFolder Then
objFS.createFolder DestFolder
End If

For Each objF1 In objFiles
FileCopy srcFolder & "\" & objF1.Name, DestFolder & "\" &
objF1.Name
Next
End Function



I want to
automate the creation of users files. How can I do it using VBA ?



Function createXL()
Dim appXL As Object
Dim wrkBuk As Object


Set appXL = CreateObject("Excel.Application")
appXL.Visible = True
Set wrkBuk = appXL.Workbooks.Add

appXL.Cells(1,1).Value = Sheets("Sheet1").Cells(1,1).Value


wrkBuk.Saveas "C:\NewBuk.xls"
wrkBuk.Close
Set appXL = nothing
End Function

Hope this will help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Create new excel files, Save backup of excel file

Hello,

Thank you for your help.

One more problem:

Function BackUp(...) causes run time error 70 on:
FileCopy srcFolder & "\" & objF1.Name, DestFolder & "\" & objF1.Name
It creates destination folder but does not copy files from source
folder into it..
How can I solve this ?

Function createXL() works great.

Thank you for your help.
Gil D.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Create new excel files, Save backup of excel file

the files that you will going to backUp is opened, that's why it has
a runtime error.

Close first all the files in that folder and run again the BackUp
function.


HTH

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Create new excel files, Save backup of excel file

Hello,

Thank you for your answer.

I want that my user will be able to backup my application within excel
(My application is an excel file).
I understand (from your answer) that it is not possible.
Should I create another excel workbook with backup function in order to
do this ?

Thank you
Gil D.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Create new excel files, Save backup of excel file

No need to create another xls.


Function BackUp(srcFolder As String, DestFolder As String, createFolder
As Boolean)
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(srcFolder)
Set objFiles = objFolder.Files


If createFolder Then
objFS.createFolder DestFolder
End If


For Each objF1 In objFiles
If objF1.Name < ThisWorkbook.Name Then
FileCopy srcFolder & "\" & objF1.Name, DestFolder & "\" &
objF1.Name
Else
ThisWorkbook.SaveAs DestFolder & "\" & ThisWorkbook.Name
End If
Next
End Function

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Create new excel files, Save backup of excel file

No need to create another xls.


Function BackUp(srcFolder As String, DestFolder As String, createFolder
As Boolean)
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(srcFolder)
Set objFiles = objFolder.Files


If createFolder Then
objFS.createFolder DestFolder
End If


For Each objF1 In objFiles
if objF1.Name < ThisWorkbook.Name then
FileCopy srcFolder & "\" & objF1.Name, DestFolder & "\" &
objF1.Name
else
ThisWorkbook.SaveAs DestFolder & "\" & ThisWorkbook.Name
End if
Next
End Function

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create an automatic backup file on open in EXCEL? bjohnsonnc Excel Discussion (Misc queries) 1 September 20th 07 04:45 PM
Set Excel 2000 to automatically create backup file. Steve Zed Excel Discussion (Misc queries) 3 March 7th 07 05:09 PM
In Excel, I want to create a backup copy whenever I save a file. Bearpecs Excel Discussion (Misc queries) 1 June 7th 06 01:52 PM
create a separate backup file in excel when exiting backup excel files Excel Worksheet Functions 1 February 2nd 06 08:21 PM
How do I Create backup of excel file in other folder khalid Excel Discussion (Misc queries) 1 May 24th 05 11:01 AM


All times are GMT +1. The time now is 10:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"