Updating a separate workbook with new info

jbortfeld

Board Regular
Joined
Feb 24, 2005
Messages
67
Hi I have a sheet of data ("Sheet1") in my current workbook. I want to add a new workbook, copy the data from "Sheet1" into the new workbook, save the new workbook as "G:\Folder\Workbook1.csv", overwrite any existing file of the same name, and close - all without stopping me to ask for permission.

So basically every week I want to take a bunch of data that I produce, and create/update a workbook with the same name every week. The data from the previous week should be erased prior to the addition of the current data.

I am doing it a really long way that takes much more time than I think is necessary.

Workbooks.Open ("G:\Folder\Workbook1.csv")

For i = 1 To compcount
For j = 1 To 256
Workbooks("CurrentData.xls").Worksheets("Sheet1").Cells(i, j).Copy Destination:=Workbooks("Workbook1.csv").Worksheets(1).Cells(i, j)
Next j
Next i

Workbooks("Workbook1.csv").Save
Workbooks("Workbook1.csv").Close

It's a pretty unsophisticated way of doing it but it works. I'm hoping though someone can teach me a new trick.

Thank you.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Another thing:

Basically I'm just looking to overwrite the preexisting file with new data.

(And in the code I copied above, I forgot to add that I clear the info right after I open the workbook)
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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